Part Number Hot Search : 
1N524 RLZ16 150U080 CX550 1002T EDC15 HK160 H07N60E
Product Description
Full Text Search
 

To Download PIC24F16KA102T-I Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2008-2011 microchip technology inc. ds39927c pic24f16ka102 family data sheet 20/28-pin general purpose, 16-bit flash microcontrollers with nanowatt xlp technology
ds39927c-page 2 ? 2008-2011 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, pic 32 logo, rfpic and uni/o are registered trademarks of microchip technology incorporated in the u.s.a. and other countries. filterlab, hampshire, hi-tech c, linear active thermistor, mxdev, mxlab, seeval and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, app lication maestro, chipkit, chipkit logo, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, hi-tide, in-circuit serial programming, icsp, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, omniscient code generation, picc, picc-18, picdem, picdem.net, pickit, pictail, real ice, rflab, select mode, total endurance, tsharc, uniwindriver, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2008-2011, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. isbn: 978-1-61341-690-7 note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specifications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2009 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2008-2011 microchip technology inc. ds39927c-page 3 pic24f16ka102 family power management modes: ? run ? cpu, flash, sram and peripherals on ? doze ? cpu clock runs slower than peripherals ? idle ? cpu off, flash, sram and peripherals on ? sleep ? cpu, flash and peripherals off and sram on ? deep sleep ? cpu, flash, sram and most peripherals off: - run mode currents down to 8 ? a typical - idle mode currents down to 2 ? a typical - deep sleep mode currents down to 20 na typical - rtcc 490 na, 32 khz, 1.8v - watchdog timer 350 na, 1.8v typical high-performance cpu: ? modified harvard architecture ? up to 16 mips operation @ 32 mhz ? 8 mhz internal oscillator with 4x pll option and multiple divide options ? 17-bit by 17-bit single-cycle hardware multiplier ? 32-bit by 16-bit hardware divider ? 16-bit x 16-bit working register array ? c compiler optimized instruction set architecture peripheral features: ? hardware real-time clock and calendar (rtcc): - provides clock, calendar and alarm functions - can run in deep sleep mode ? programmable cyclic redundancy check (crc) ? serial communication modules: - spi, i 2 c? and two uart modules ? three 16-bit timers/counters with programmable prescaler ? 16-bit capture inputs ? 16-bit compare/pwm output ? configurable open-drain outputs on digital i/o pins ? up to three external interrupt sources analog features: ? 10-bit, up to 9-channel analog-to-digital converter: - 500 ksps conversion rate - conversion available during sleep and idle ? dual analog comparators with programmable input/ output configuration ? charge time measurement unit (ctmu): - used for capacitance sensing - time measurement, down to 1 ns resolution - delay/pulse generation, down to 1 ns resolution special microcontroller features: ? operating voltage range of 1.8v to 3.6v ? high-current sink/source (18 ma/18 ma) on all i/o pins ? flash program memory: - erase/write cycles: 10,000 minimum - 40-years? data retention minimum ? data eeprom: - erase/write cycles: 100,000 minimum - 40-years? data retention minimum ? fail-safe clock monitor ? system frequency range declaration bits: - declaring the frequency range optimizes the current consumption. ? flexible watchdog timer (wdt) with on-chip, low-power rc oscillator for reliable operation ? in-circuit serial programming? (icsp?) and in-circuit debug (icd) via two pins ? programmable high/low-voltage detect (hlvd) ? brown-out reset (bor): - standard bor with three programmable trip points; can be disabled in sleep ? extreme low-power dsbor for deep sleep, lpbor for all other modes pic24f device pins program memory (bytes) sram (bytes) data eeprom (bytes) timers 16-bit capture input output compare/ pwm uart/ irda ? i 2 c? 10-bit a/d (ch) comparators ctmu (ch) rtcc spi 08ka101 20 8k 1.5k 512 3 1 1 2 1 1 9 2 9 y 16ka101 20 16k 1.5k 512 3 1 1 2 1 1 9 2 9 y 08ka102 28 8k 1.5k 512 3 1 1 2 1 1 9 2 9 y 16ka102 28 16k 1.5k 512 3 1 1 2 1 1 9 2 9 y 20/28-pin general purpose, 16-bit flash microcontrollers with nanowatt xlp technology
pic24f16ka102 family ds39927c-page 4 ? 2008-2011 microchip technology inc. pin diagrams pic24xxkax01 1 2 3 4 5 6 7 8 9 10 20 19 18 17 16 15 14 13 12 11 20-pin pdip, ssop, soic (2) mclr / v pp /ra5 osco/clko/an5/c1ina/c2inc/cn29/ra3 pgc2/an0/v ref +/cn2/ra0 pgd2/an1/v ref -/cn3/ra1 pgd1/an2/c1ind/c2inb/u2tx/cn4/rb0 pgc3/sosco/t1ck/u2cts /cn0/ra4 pgd3/sosci/u2rts /u2bclk/cn1/rb4 osci/clki/an4/c1inb/c2ind/cn30/ra2 u1rx/cn6/rb2 pgc1/an3/c1inc/c2ina/u2rx/cn5/rb1 v dd v ss u1tx/int0/cn23/rb7 u1cts /scl1/cn22/rb8 refo/ss1 /t2ck/t3ck/cn11/rb15 an10/cv ref /rtcc/sdi1/ocfa/c1out/int1/cn12/rb14 an11/sdo1/ctpls/cn13/rb13 an12/hlvdin/sck1/cted2/cn14/rb12 u1rts /u1bclk/sda1/cn21/rb9 oc1/ic1/c2out/int2/cted1/cn8/ra6 pic24fxxkax02 1 2 3 4 5 6 7 8 9 10 11 12 13 14 28 27 26 25 24 23 22 21 20 19 18 17 16 15 28-pin spdip, ssop, soic (2) mclr /v pp /ra5 v ss v dd an0/v ref +/cn2/ra0 an1/v ref -/cn3/ra1 pgd1/an2/c1ind/c2inb/u2tx/cn4/rb0 sosco/t1ck/u2cts /cn0/ra4 sosci/u2rts /u2bclk/cn1/rb4 osco/clko/cn29/ra3 osci/clki/cn30/ra2 an5/c1ina/c2inc/cn7/rb3 an4/c1inb/c2ind/u1rx/cn6/rb2 pgc1/an3/c1inc/c2ina/u2rx/cn5/rb1 pgd3/sda1 (1) /cn27/rb5 v dd v ss pgc3/scl1 (1 ) /cn24/rb6 ic1/cn9/ra7 oc1/c2out/int2/cted1/cn8/ra6 u1tx/int0/cn23/rb7 u1rts /u1bclk/sda1/cn21/rb9 u1cts /scl1/cn22/rb8 refo/ss1 /t2ck/t3ck/cn11/rb15 an10/cv ref /rtcc/ocfa/c1out/int1/cn12/rb14 an11/sdo1/ctpls/cn13/rb13 an12/hlvdin/cted2/cn14/rb12 pgd2/sdi1/pmd2/cn16/rb10 pgc2/sck1/cn15/rb11 note 1: alternative multiplexing for sda1 and scl1 when the i2csel configuration bit is set. 2: all device pins have a maximum voltage of 3.6v and are not 5v tolerant.
? 2008-2011 microchip technology inc. ds39927c-page 5 pic24f16ka102 family pin diagrams (continued) 89 2 3 1 12 13 14 15 10 6 11 16 17 18 19 20 7 pic24fxxka102 5 4 mclr /v pp /ra5 pgc2/an0/v ref +/cn2/ra0 pgd2/an1/v ref -/cn3/ra1 v dd v ss pgd1/an2/c1ind/c2inb/u2tx/cn4/rb0 pgc3/sosco/t1ck/u2cts /cn0/ra4 pgd3/sosci/u2rts /cn1/u2bclk/rb4 osco/clko/an5/c1ina/c2inc/cn29/ra3 osci/clki/an4/c1inb/c2ind/cn30/ra2 oc1/ic1/c2out/int2/cted1/cn8/ra6 u1tx/int0/cn23/rb7 an10/cv ref /rtcc/sdi1/ocfa/c1out/int1/cn12/rb14 u1cts /scl1/cn22/rb8 u1rx/cn6/rb2 pgc1/an3/c1inc/c2ina/u2rx/cn5/rb1 an11/sdo1/ctpls/ cn13/rb13 an12/hlvdin/sck1/cted2/cn14/rb12 u1rts /u1bclk/sda1/cn21/rb9 refo/ss1 /t2ck / t3ck/cn11/rb15 note 1: the bottom pad of the qfn package should be connected to v ss . 2: all device pins have a maximum voltage of 3.6v and are not 5v tolerant. 20-pin qfn (1,2)
pic24f16ka102 family ds39927c-page 6 ? 2008-2011 microchip technology inc. pin diagrams (continued) note 1: alternative multiplexing for sda1 and scl1 when the i2csel configuration bit is set. 2: the bottom pad of the qfn package should be connected to v ss . 3: all device pins have a maximum voltage of 3.6v and are not 5v tolerant. 28-pin qfn (2,3) 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 8 7 16 17 23 24 25 26 27 28 9 pic24fxxka102 5 4 v ss pgd1/an2/c1ind/c2inb/u2tx/cn4/rb0 osco/clko/cn29/ra3 osci/clki/cn30/ra2 an5/c1ina/c2inc/cn7/rb3 an4/c1inb/c2ind/u1rx/cn6/rb2 pgc1/an3/c1inc/c2ina/u2rx/cn5/rb1 ic1/cn9/ra7 oc1/c2out/int2/cted1/cn8/ra6 u1rts /u1bclk/sda1/cn21/rb9 an11/sdo1/ctpls/cn13/rb13 an12/hlvdin/cted2/cn14/rb12 pgd2/sdi1/pmd2/cn16/rb10 pgc2/sck1/cn15/rb11 v dd pgc3/scl1 (1) /cn24/rb6 sosco/t1ck/u2cts /cn0/ra4 sosci/u2rts /u2bclk/cn1/rb4 u1tx/int0/cn23/rb7 u1cts /scl1/cn22/rb8 pgd3/sda1 (1) /cn27/rb5 mclr /v pp /ra5 an0/v ref +/cn2/ra0 an1/v ref -/cn3/ra1 v dd vss refo/ss1 /t2ck/t3ck/cn11/rb15 an10/cv ref /rtcc/ocfa/c1out/int1/cn12/rb14
? 2008-2011 microchip technology inc. ds39927c-page 7 pic24f16ka102 family table of contents 1.0 device overview ............................................................................................................. ............................................................. 9 2.0 guidelines for getting started with 16-bit microcontrollers................................................................. ....................................... 17 3.0 cpu ........................................................................................................................ ................................................................... 23 4.0 memory organization ......................................................................................................... ........................................................ 29 5.0 flash program memory........................................................................................................ ...................................................... 45 6.0 data eeprom memory .......................................................................................................... ................................................... 51 7.0 resets ...................................................................................................................... .................................................................. 57 8.0 interrupt controller ........................................................................................................ ............................................................. 63 9.0 oscillator configuration ....................................... ............................................................. .......................................................... 91 10.0 power-saving features...................................................................................................... ...................................................... 101 11.0 i/o ports .................................................................................................................. ................................................................. 113 12.0 timer1 .................................................................................................................... ................................................................. 115 13.0 timer2/3 ................................................................................................................... ................................................................ 117 14.0 input capture.............................................................................................................. .............................................................. 123 15.0 output compare............................................................................................................. .......................................................... 125 16.0 serial peripheral interface (spi).......................................................................................... ..................................................... 131 17.0 inter-integrated circuit (i 2 c?) ............................................................................................................................ ..................... 139 18.0 universal asynchronous receiver transmitter (uart) ......................................................................... .................................. 147 19.0 real-time clock and calendar (rtcc) ....................................................................................... ........................................... 155 20.0 programmable cyclic redundancy check (crc) generator ....................................................................... ........................... 167 21.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 171 22.0 10-bit high-speed a/d converter ............................................................................................ ................................................ 173 23.0 comparator module.......................................................................................................... ........................................................ 183 24.0 comparator voltage reference............................................................................................... ................................................. 187 25.0 charge time measurement unit (ctmu) ........................................................................................ ........................................ 189 26.0 special features ........................................................................................................... ........................................................... 193 27.0 development support........................................................................................................ ....................................................... 203 28.0 instruction set summary .................................................................................................... ...................................................... 207 29.0 electrical characteristics ................................................................................................. ......................................................... 215 30.0 packaging information...................................................................................................... ........................................................ 251 appendix a: revision history................................................................................................... .......................................................... 269 index .......................................................................................................................... ........................................................................ 271 the microchip web site ......................................................................................................... ............................................................ 275 customer change notification service ........................................................................................... ................................................... 275 customer support............................................................................................................... ............................................................... 275 reader response ................................................................................................................ .............................................................. 276 product identification system .................................................................................................. .......................................................... 277
pic24f16ka102 family ds39927c-page 8 ? 2008-2011 microchip technology inc. to our valued customers it is our intention to provide our valued customers with the be st documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regardi ng this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
? 2008-2011 microchip technology inc. ds39927c-page 9 pic24f16ka102 family 1.0 device overview this document contains device-specific information for the following devices: ? pic24f08ka101 ? pic24f16ka101 ? pic24f08ka102 ? pic24f16ka102 the pic24f16ka102 family introduces a new line of extreme low-power microchip devices: a 16-bit micro- controller family with a broad peripheral feature set and enhanced computational performance. it also offers a new migration option for those high-performance appli- cations, which may be outgrowing their 8-bit platforms, but do not require the numerical processing power of a digital signal processor. 1.1 core features 1.1.1 16-bit architecture central to all pic24f devices is the 16-bit modified harvard architecture, first introduced with microchip?s dspic ? digital signal controllers. the pic24f cpu core offers a wide range of enhancements, such as: ? 16-bit data and 24-bit address paths with the ability to move information between data and memory spaces ? linear addressing of up to 12 mbytes (program space) and 64 kbytes (data) ? a 16-element working register array with built-in software stack support ? a 17 x 17 hardware multiplier with support for integer math ? hardware support for 32-bit by 16-bit division ? an instruction set that supports multiple addressing modes and is optimized for high-level languages, such as c ? operational performance up to 16 mips 1.1.2 power-saving technology all of the devices in the pic24f16ka102 family incorporate a range of features that can significantly reduce power consumption during operation. key items include: ? on-the-fly clock switching: the device clock can be changed under software control to the timer1 source or the internal, low-power rc oscillator during operation, allowing users to incorporate power-saving ideas into their software designs. ? doze mode operation: when timing-sensitive applications, such as serial communications, require the uninterrupted operation of peripherals, the cpu clock speed can be selectively reduced, allowing incremental power savings without missing a beat. ? instruction-based power-saving modes: there are three instruction-based power-saving modes: - idle mode: the core is shut down while leaving the peripherals active. - sleep mode: the core and peripherals that require the system clock are shut down, leaving the peripherals that use their own clock, or the clock from other devices, active. - deep sleep mode: the core, peripherals (except rtcc and dswdt), flash and sram are shut down. 1.1.3 oscillator options and features the pic24f16ka102 family offers five different oscillator options, allowing users a range of choices in developing application hardware. these include: ? two crystal modes using crystals or ceramic resonators. ? two external clock modes offering the option of a divide-by-2 clock output. ? two fast internal oscillators (frcs): one with a nominal 8 mhz output and the other with a nominal 500 khz output. these outputs can also be divided under software control to provide clock speed as low as 31 khz or 2 khz. ? a phase locked loop (pll) frequency multiplier, available to the external oscillator modes and the 8 mhz frc oscillator, which allows clock speeds of up to 32 mhz. ? a separate internal rc oscillator (lprc) with a fixed 31 khz output, which provides a low-power option for timing-insensitive applications.
pic24f16ka102 family ds39927c-page 10 ? 2008-2011 microchip technology inc. the internal oscillator block also provides a stable reference source for the fail-safe clock monitor (fscm). this option constantly monitors the main clock source against a reference signal provided by the internal oscillator and enables the controller to switch to the internal oscillator, allowing for continued low-speed operation or a safe application shutdown. 1.1.4 easy migration regardless of the memory size, all the devices share the same rich set of peripherals, allowing for a smooth migration path as applications grow and evolve. the consistent pinout scheme used throughout the entire family also helps in migrating to the next larger device. this is true when moving between devices with the same pin count, or even jumping from 20-pin to 28-pin devices. the pic24f family is pin compatible with devices in the dspic33 family, and shares some compatibility with the pinout schema for pic18 and dspic30. this extends the ability of applications to grow from the relatively simple, to the powerful and complex. 1.2 other special features ? communications: the pic24f16ka102 family incorporates a range of serial communication peripherals to handle a range of application requirements. there is an i 2 c? module that supports both the master and slave modes of operation. it also comprises uarts with built-in irda ? encoders/decoders and an spi module. ? real-time clock/calendar: this module implements a full-featured clock and calendar with alarm functions in hardware, freeing up timer resources and program memory space for use of the core application. ? 10-bit a/d converter: this module incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period, and faster sampling speed. the 16-deep result buffer can be used either in sleep to reduce power, or in active mode to improve throughput. ? charge time measurement unit (ctmu) interface: the pic24f16ka102 family includes the new ctmu interface module, which can be used for capacitive touch sensing, proximity sensing and also for precision time measurement and pulse generation. 1.3 details on individual family members devices in the pic24f16ka102 family are available in 20-pin and 28-pin packages. the general block diagram for all devices is displayed in figure 1-1 . the devices are different from each other in two ways: 1. flash program memory (8 kbytes for pic24f08ka devices, 16 kbytes for pic24f16ka devices). 2. available i/o pins and ports (18 pins on two ports for 20-pin devices and 24 pins on two ports for 28-pin devices). 3. alternate sclx and sdax pins are available only in 28-pin devices and not in 20-pin devices. all other features for devices in this family are identical; these are summarized in ta b l e 1 - 1 . a list of the pin features available on the pic24f16ka102 family devices, sorted by function, is provided in table 1-2 . note: table 1-1 provides the pin location of individual peripheral features and not how they are multiplexed on the same pin. this information is provided in the pinout diagrams on pages 4 , 5 and 6 of the data sheet. multiplexed features are sorted by the priority given to a feature, with the highest priority peripheral being listed first.
? 2008-2011 microchip technology inc. ds39927c-page 11 pic24f16ka102 family table 1-1: device features for the pic24f16ka102 family features pic24f08ka101 pic24f16ka101 pic24f08ka102 pic24f16ka102 operating frequency dc ? 32 mhz program memory (bytes) 8k 16k 8k 16k program memory (instructions) 2816 5632 2816 5632 data memory (bytes) 1536 data eeprom memory (bytes) 512 interrupt sources (soft vectors/nmi traps) 30 (26/4) i/o ports porta<6:0> portb<15:12, 9:7, 4, 2:0> porta<7:0> portb<15:0> total i/o pins 18 24 timers: total number (16-bit) 32-bit (from paired 16-bit timers) 3 1 input capture channels 1 output compare/pwm channels 1 input change notification interrupt 17 23 serial communications: uart spi (3-wire/4-wire) i 2 c? 2 1 1 10-bit analog-to-digital module (input channels) 9 analog comparators 2 resets (and delays) por, bor, reset instruction, mclr , wdt, illegal opcode, repeat instruction, hardware traps, configuration word mismatch (pwrt, ost, pll lock) instruction set 76 base instructions, multiple addressing mode variations packages 20-pin pdip/ssop/soic /qfn 28-pin spdip/ssop/soic/qfn
pic24f16ka102 family ds39927c-page 12 ? 2008-2011 microchip technology inc. figure 1-1: pic24f16ka102 family general block diagram instruction decode and control 16 pch pcl 16 program counter 16-bit alu 23 24 data bus inst register 16 divide support inst latch 16 ea mux read agu write agu 16 16 8 interrupt controller psv and table data access control block stack control logic repeat control logic data latch data ram address latch address latch program memory data latch 16 address bus literal data 23 control signals 16 16 16 x 16 w reg array multiplier 17x17 porta (1) ra<0:7> portb (1) rb<0:15> note 1: all pins or features are not implemented on all device pi nout configurations. see table 1-2 for i/o port pin descriptions. comparators timer2/3 timer1 ctmu ic1 a/d 10-bit oc1/pwm spi1 i2c1 cn1-22 (1) uart1/2 data eeprom osci/clki osco/clko v dd , timing generation v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor precision reference band gap frc/lprc oscillators dswdt rtcc hlvd refo
? 2008-2011 microchip technology inc. ds39927c-page 13 pic24f16ka102 family table 1-2: pic24f16ka102 fa mily pinout descriptions function pin number i/o input buffer description 20-pin pdip/ssop/ soic 20-pin qfn 28-pin spdip/ ssop/soic 28-pin qfn an0 2 19 2 27 i ana a/d analog inputs an1 3 20 3 28 i ana an2 4 1 4 1 i ana an3 5 2 5 2 i ana an4 7 4 6 3 i ana an5 8 5 7 4 i ana an10 17 14 25 22 i ana an11 16 13 24 21 i ana an12 15 12 23 20 i ana u1bclk 13 10 18 15 o ? uart1 irda ? baud clock u2bclk 9 6 11 8 o ? uart2 irda baud clock c1ina 8 5 7 4 i ana comparator 1 input a (positive input) c1inb 7 4 6 3 i ana comparator 1 input b (negative input option 1) c1inc 5 2 5 2 i ana comparator input c (negative input option 2) c1ind 4 1 4 1 i ana comparator input d (negative input option 3) c1out 17 14 25 22 o ? comparator 1 output c2ina 5 2 5 2 i ana comparator 2 input a (positive input) c2inb 4 1 4 1 i ana comparator 2 input b (negative input option 1) c2inc 8 5 7 4 i ana comparator 2 input c (negative input option 2) c2ind 7 4 6 3 i ana comparator 2 input d (negative input option 3) c2out 14 11 20 17 o ? comparator 2 output clki 7 4 9 6 i ana main clock input connection clko 8 5 10 7 o ? system clock output legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer note 1: alternative multiplexing when the i2c1sel configuration bit is cleared.
pic24f16ka102 family ds39927c-page 14 ? 2008-2011 microchip technology inc. cn0 10 7 12 9 i st interrupt-on-change inputs cn1 9 6 11 8 i st cn2 2 19 2 27 i st cn3 3 20 3 28 i st cn4 4 1 4 1 i st cn5 5 2 5 2 i st cn6 6 3 6 3 i st cn7 ? ? 7 4 i st cn8 14 11 20 17 i st cn9 ? ? 19 16 i st cn11 18 15 26 23 i st cn1217142522ist cn1316132421ist cn1415122320ist cn15 ? ? 22 19 i st cn16 ? ? 21 18 i st cn2113101815ist cn22 12 9 17 14 i st cn23 11 8 16 13 i st cn24 ? ? 15 12 i st cn27 ? ? 14 11 i st cn2985107ist cn30 7 4 9 6 i st cv ref 17 14 25 22 o ana comparator voltage reference output cted1 14 11 20 17 i st ctmu trigger edge input 1 cted2 15 12 23 20 i st ctmu trigger edge input 2 ctpls 16 13 24 21 o ? ctmu pulse output ic1 14 11 19 16 i st input capture 1 input int0 11 8 16 13 i st external interrupt inputs int1 17 14 25 22 i st int2 14 11 20 17 i st hlvdin 15 12 23 20 i ana hlvd voltage input mclr 1 18 1 26 i st master clear (device reset) input oc1 14 11 20 17 o ? output compare/pwm outputs ocfa 17 14 25 22 i ? output compare fault a osci 7 4 9 6 i ana main oscillator input connection osco 8 5 10 7 o ana main oscillator output connection table 1-2: pic24f16ka102 family pinout descriptions (continued) function pin number i/o input buffer description 20-pin pdip/ssop/ soic 20-pin qfn 28-pin spdip/ ssop/soic 28-pin qfn legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer note 1: alternative multiplexing when the i2c1sel configuration bit is cleared.
? 2008-2011 microchip technology inc. ds39927c-page 15 pic24f16ka102 family pgc1 5 2 5 2 i/o st in-circuit debugger and icsp? programming clock pgd1 4 1 4 1 i/o st in-circuit debugger and icsp programming data pgc2 2 19 22 19 i/o st in-circuit debugger and icsp programming clock pgd2 3 20 21 18 i/o st in-circuit debugger and icsp programming data pgc3 10 7 15 12 i/o st in-circuit debugger and icsp programming clock pgd3 9 6 14 11 i/o st in-circuit debugger and icsp programming data ra0 2 19 2 27 i/o st porta digital i/o ra1 3 20 3 28 i/o st ra2 7 4 9 6 i/o st ra3 8 5 10 7 i/o st ra4 10 7 12 9 i/o st ra5 1 18 1 26 i/o st ra6 14 11 20 17 i/o st ra7 ? ? 19 16 i/o st rb0 4 1 4 1 i/o st portb digital i/o rb1 5 2 5 2 i/o st rb2 6 3 6 3 i/o st rb3 ? ? 7 4 i/o st rb4 9 6 11 8 i/o st rb5 ? ? 14 11 i/o st rb6 ? ? 15 12 i/o st rb7 11 8 16 13 i/o st rb8 12 9 17 14 i/o st rb9 13 10 18 15 i/o st rb10 ? ? 21 18 i/o st rb11 ? ? 22 19 i/o st rb12 15 12 23 20 i/o st rb13 16 13 24 21 i/o st rb14 17 14 25 22 i/o st rb15 18 15 26 23 i/o st refo 18 15 26 23 o ? reference clock output rtcc 17 14 25 22 o ? real-time clock alarm output sck1 15 12 22 19 i/o st spi1 serial clock input/output scl1 12 9 17, 15 ( 1 ) 14, 12 ( 1 ) i/o i 2 c i2c1 synchronous serial clock input/output sda1 13 10 18, 14 ( 1 ) 15, 11 ( 1 ) i/o i 2 c i2c1 data input/output sdi1 17 14 21 18 i st spi1 serial data input sdo1 16 13 24 21 o ? spi1 serial data output sosci 9 6 11 8 i ana secondary oscillator input sosco 10 7 12 9 o ana secondary oscillator output ss1 18 15 26 23 i/o st slave select input/frame select output (spi1) table 1-2: pic24f16ka102 family pinout descriptions (continued) function pin number i/o input buffer description 20-pin pdip/ssop/ soic 20-pin qfn 28-pin spdip/ ssop/soic 28-pin qfn legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer note 1: alternative multiplexing when the i2c1sel configuration bit is cleared.
pic24f16ka102 family ds39927c-page 16 ? 2008-2011 microchip technology inc. t1ck 10 7 12 9 i st timer1 clock t2ck 18 15 26 23 i st timer2 clock t3ck 18 15 26 23 i st timer3 clock u1cts 12 9 17 14 i st uart1 clear to send input u1rts 13 10 18 15 o ? uart1 request to send output u1rx 6 3 6 3 i st uart1 receive u1tx 11 8 16 13 o ? uart1 transmit output v dd 20 17 13, 28 10, 25 p ? positive supply for peripheral digital logic and i/o pins v pp 1 18 1 26 p ? programming mode entry voltage v ref - 3 20 3 28 i ana a/d and comparator reference voltage (low) input v ref + 2 19 2 27 i ana a/d and comparator reference voltage (high) input v ss 19 16 8, 27 5, 24 p ? ground reference for logic and i/o pin table 1-2: pic24f16ka102 family pinout descriptions (continued) function pin number i/o input buffer description 20-pin pdip/ssop/ soic 20-pin qfn 28-pin spdip/ ssop/soic 28-pin qfn legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer note 1: alternative multiplexing when the i2c1sel configuration bit is cleared.
? 2008-2011 microchip technology inc. ds39927c-page 17 pic24f16ka102 family 2.0 guidelines for getting started with 16-bit microcontrollers 2.1 basic connection requirements getting started with the pic24f16ka102 family family of 16-bit microcontrollers requires attention to a minimal set of device pin connections before proceeding with development. the following pins must always be connected: ?all v dd and v ss pins (see section 2.2 ?power supply pins? ) ?all av dd and av ss pins, regardless of whether or not the analog device features are used (see section 2.2 ?power supply pins? ) ?mclr pin (see section 2.3 ?master clear (mclr) pin? ) ?v cap pins (see section 2.4 ?voltage regulator pin (v cap )? ) these pins must also be connected if they are being used in the end application: ? pgecx/pgedx pins used for in-circuit serial programming? (icsp?) and debugging purposes (see section 2.5 ?icsp pins? ) ? osci and osco pins when an external oscillator source is used (see section 2.6 ?external oscillator pins? ) additionally, the following pins may be required: ?v ref +/v ref - pins are used when external voltage reference for analog modules is implemented the minimum mandatory connections are shown in figure 2-1 . figure 2-1: recommended minimum connections note: the av dd and av ss pins must always be connected, regardless of whether any of the analog modules are being used. pic24fxxkxx v dd v ss v dd v ss v ss v dd av dd av ss v dd v ss c1 r1 v dd mclr v cap r2 c7 c2 (2) c3 (2) c4 (2) c5 (2) c6 (2) key (all values are recommendations): c1 through c6: 0.1 ? f, 20v ceramic c7: 10 ? f, 16v tantalum or ceramic r1: 10 k ? r2: 100 ? to 470 ? note 1: see section 2.4 ?voltage regulator pin (v cap )? for explanation of v cap pin connections. 2: the example shown is for a pic24f device with five v dd /v ss and av dd /av ss pairs. other devices may have more or less pairs; adjust the number of decoupling capacitors appropriately. 3: some pic24f k parts do not have a regulator. (1) (3)
pic24f16ka102 family ds39927c-page 18 ? 2008-2011 microchip technology inc. 2.2 power supply pins 2.2.1 decoupling capacitors the use of decoupling capacitors on every pair of power supply pins, such as v dd , v ss , av dd and av ss , is required. consider the following criteria when using decoupling capacitors: ? value and type of capacitor: a 0.1 ? f (100 nf), 10-20v capacitor is recommended. the capacitor should be a low-esr device, with a resonance frequency in the range of 200 mhz and higher. ceramic capacitors are recommended. ? placement on the printed circuit board: the decoupling capacitors should be placed as close to the pins as possible. it is recommended to place the capacitors on the same side of the board as the device. if space is constricted, the capacitor can be placed on another layer on the pcb using a via; however, ensure that the trace length from the pin to the capacitor is no greater than 0.25 inch (6 mm). ? handling high-frequency noise: if the board is experiencing high-frequency noise (upward of tens of mhz), add a second ceramic type capaci- tor in parallel to the above described decoupling capacitor. the value of the second capacitor can be in the range of 0.01 ? f to 0.001 ? f. place this second capacitor next to each primary decoupling capacitor. in high-speed circuit designs, consider implementing a decade pair of capacitances as close to the power and ground pins as possible (e.g., 0.1 ? f in parallel with 0.001 ? f). ? maximizing performance: on the board layout from the power supply circuit, run the power and return traces to the decoupling capacitors first, and then to the device pins. this ensures that the decoupling capacitors are first in the power chain. equally important is to keep the trace length between the capacitor and the power pins to a minimum, thereby reducing pcb trace inductance. 2.2.2 tank capacitors on boards with power traces running longer than six inches in length, it is suggested to use a tank capac- itor for integrated circuits, including microcontrollers, to supply a local power source. the value of the tank capacitor should be determined based on the trace resistance that connects the power supply source to the device, and the maximum current drawn by the device in the application. in other words, select the tank capacitor so that it meets the acceptable voltage sag at the device. typical values range from 4.7 ? f to 47 ? f. 2.3 master clear (mclr ) pin the mclr pin provides two specific device functions: device reset, and device programming and debugging. if programming and debugging are not required in the end application, a direct connection to v dd may be all that is required. the addition of other components, to help increase the application?s resistance to spurious resets from voltage sags, may be beneficial. a typical configuration is shown in figure 2-1 . other circuit designs may be implemented, depending on the application?s requirements. during programming and debugging, the resistance and capacitance that can be added to the pin must be considered. device programmers and debuggers drive the mclr pin. consequently, specific voltage levels (v ih and v il ) and fast signal transitions must not be adversely affected. therefore, specific values of r1 and c1 will need to be adjusted based on the application and pcb requirements. for example, it is recommended that the capacitor, c1, be isolated from the mclr pin during programming and debugging operations by using a jumper ( figure 2-2 ). the jumper is replaced for normal run-time operations. any components associated with the mclr pin should be placed within 0.25 inch (6 mm) of the pin. figure 2-2: example of mclr pin connections note 1: r1 ?? 10 k ? is recommended. a suggested starting value is 10 k ? . ensure that the mclr pin v ih and v il specifications are met. 2: r2 ?? 470 ? will limit any current flowing into mclr from the external capacitor, c, in the event of mclr pin breakdown, due to electrostatic discharge (esd) or electrical overstress (eos). ensure that the mclr pin v ih and v il specifications are met. c1 r2 r1 v dd mclr pic24fxxkxx jp
? 2008-2011 microchip technology inc. ds39927c-page 19 pic24f16ka102 family 2.4 voltage regulator pin (v cap ) some of the pic24f k devices have an internal voltage regulator. these devices have the voltage regulator output brought out on the v cap pin. on the pic24f k devices with regulators, a low-esr (< 5 ? ) capacitor is required on the v cap pin to stabilize the voltage regulator output. the v cap pin must not be connected to v dd and must use a capacitor of 10 f connected to ground. the type can be ceramic or tantalum. suitable examples of capacitors are shown in table 2-1 . capacitors with equivalent specifications can be used. designers may use figure 2-3 to evaluate esr equivalence of candidate devices. the placement of this capacitor should be close to v cap . it is recommended that the trace length not exceed 0.25 inch (6 mm). refer to section 29.0 ?electrical characteristics? for additional information. refer to section 29.0 ?electrical characteristics? for information on v dd and v ddcore . figure 2-3: frequency vs. esr performance for suggested v cap note: this section applies only to pic24f k devices with an on-chip voltage regulator. 10 1 0.1 0.01 0.001 0.01 0.1 1 10 100 1000 10,000 frequency (mhz) esr ( ? ) note: typical data measurement at 25c, 0v dc bias. table 2-1: suitable capacitor equivalents make part # nominal capacitance base tolerance rated voltage temp. range tdk c3216x7r1c106k 10 f 10% 16v -55 to 125oc tdk c3216x5r1c106k 10 f 10% 16v -55 to 85oc panasonic ecj-3yx1c106k 10 f 10% 16v -55 to 125oc panasonic ecj-4yb1c106k 10 f 10% 16v -55 to 85oc murata grm32dr71c106ka01l 10 f 10% 16v -55 to 125oc murata grm31cr61c106kc31l 10 f 10% 16v -55 to 85oc
pic24f16ka102 family ds39927c-page 20 ? 2008-2011 microchip technology inc. 2.4.1 considerations for ceramic capacitors in recent years, large value, low-voltage, surface-mount ceramic capacitors have become very cost effective in sizes up to a few tens of microfarad. the low-esr, small physical size and other properties make ceramic capacitors very attractive in many types of applications. ceramic capacitors are suitable for use with the inter- nal voltage regulator of this microcontroller. however, some care is needed in selecting the capacitor to ensure that it maintains sufficient capacitance over the intended operating range of the application. typical low-cost, 10 ? f ceramic capacitors are available in x5r, x7r and y5v dielectric ratings (other types are also available, but are less common). the initial toler- ance specifications for these types of capacitors are often specified as 10% to 20% (x5r and x7r), or -20%/+80% (y5v). however, the effective capacitance that these capacitors provide in an application circuit will also vary based on additional factors, such as the applied dc bias voltage and the temperature. the total in-circuit tolerance is, therefore, much wider than the initial tolerance specification. the x5r and x7r capacitors typically exhibit satisfac- tory temperature stability (ex: 15% over a wide temperature range, but consult the manufacturer's data sheets for exact specifications). however, y5v capaci- tors typically have extreme temperature tolerance specifications of +22%/-82%. due to the extreme temperature tolerance, a 10 ? f nominal rated y5v type capacitor may not deliver enough total capacitance to meet minimum internal voltage regulator stability and transient response requirements. therefore, y5v capacitors are not recommended for use with the internal regulator if the application must operate over a wide temperature range. in addition to temperature tolerance, the effective capacitance of large value ceramic capacitors can vary substantially, based on the amount of dc voltage applied to the capacitor. this effect can be very signifi- cant, but is often overlooked or is not always documented. a typical dc bias voltage vs. capacitance graph for x7r type capacitors is shown in figure 2-4 . figure 2-4: dc bias voltage vs. capacitance characteristics when selecting a ceramic capacitor to be used with the internal voltage regulator, it is suggested to select a high-voltage rating, so that the operating voltage is a small percentage of the maximum rated capacitor volt- age. for example, choose a ceramic capacitor rated at 16v for the 3.3v or 2.5v core voltage. suggested capacitors are shown in table 2-1 . 2.5 icsp pins the pgc and pgd pins are used for in-circuit serial programming? (icsp?) and debugging purposes. it is recommended to keep the trace length between the icsp connector and the icsp pins on the device as short as possible. if the icsp connector is expected to experience an esd event, a series resistor is recom- mended, with the value in the range of a few tens of ohms, not to exceed 100 ? . pull-up resistors, series diodes and capacitors on the pgc and pgd pins are not recommended as they will interfere with the programmer/debugger communica- tions to the device. if such discrete components are an application requirement, they should be removed from the circuit during programming and debugging. alter- natively, refer to the ac/dc characteristics and timing requirements information in the respective device flash programming specification for information on capacitive loading limits, and pin input voltage high (v ih ) and input low (v il ) requirements. for device emulation, ensure that the ?communication channel select? (i.e., pgcx/pgdx pins), programmed into the device, matches the physical connections for the icsp to the microchip debugger/emulator tool. for more information on available microchip development tools connection requirements, refer to section 27.0 ?development support? . -80 -70 -60 -50 -40 -30 -20 -10 0 10 5 1011121314151617 dc bias voltage (vdc) capacitance change (%) 01234 67 89 16v capacitor 10v capacitor 6.3v capacitor
? 2008-2011 microchip technology inc. ds39927c-page 21 pic24f16ka102 family 2.6 external oscillator pins many microcontrollers have options for at least two oscillators: a high-frequency primary oscillator and a low-frequency secondary oscillator (refer to section 9.0 ?oscillator configuration? for details). the oscillator circuit should be placed on the same side of the board as the device. place the oscillator circuit close to the respective oscillator pins with no more than 0.5 inch (12 mm) between the circuit components and the pins. the load capacitors should be placed next to the oscillator itself, on the same side of the board. use a grounded copper pour around the oscillator cir- cuit to isolate it from surrounding circuits. the grounded copper pour should be routed directly to the mcu ground. do not run any signal traces or power traces inside the ground pour. also, if using a two-sided board, avoid any traces on the other side of the board where the crystal is placed. layout suggestions are shown in figure 2-5 . in-line packages may be handled with a single-sided layout that completely encompasses the oscillator pins. with fine-pitch packages, it is not always possible to com- pletely surround the pins and components. a suitable solution is to tie the broken guard sections to a mirrored ground layer. in all cases, the guard trace(s) must be returned to ground. in planning the application?s routing and i/o assign- ments, ensure that adjacent port pins and other signals, in close proximity to the oscillator, are benign (i.e., free of high frequencies, short rise and fall times, and other similar noise). for additional information and design guidance on oscillator circuits, please refer to these microchip application notes, available at the corporate web site ( www.microchip.com ): ? an826, ? crystal oscillator basics and crystal selection for rfpic? and picmicro ? devices? ? an849, ?basic picmicro ? oscillator design? ? an943, ?practical picmicro ? oscillator analysis and design? ? an949, ?making your oscillator work? 2.7 unused i/os unused i/o pins should be configured as outputs and driven to a logic low state. alternatively, connect a 1 k ? to 10 k ? resistor to v ss on unused pins and drive the output to logic low. figure 2-5: suggested placement of the oscillator circuit gnd ` ` ` osc1 osc2 t1oso t1os i copper pour primary oscillator crystal timer1 oscillator crystal device pins primary oscillator c1 c2 t1 oscillator: c1 t1 oscillator: c2 (tied to ground) single-sided and in-line layouts: fine-pitch (dual-sided) layouts: gnd osco osci bottom layer copper pour oscillator crystal top layer copper pour c2 c1 device pins (tied to ground) (tied to ground)
pic24f16ka102 family ds39927c-page 22 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 23 pic24f16ka102 family 3.0 cpu the pic24f cpu has a 16-bit (data) modified harvard architecture with an enhanced instruction set and a 24-bit instruction word with a variable length opcode field. the program counter (pc) is 23 bits wide and addresses up to 4m instructions of user program memory space. a single-cycle instruction prefetch mechanism is used to help maintain throughput and provides predictable execution. all instructions execute in a single cycle, with the exception of instructions that change the program flow, the double-word move ( mov.d ) instruction and the table instructions. overhead-free program loop constructs are supported using the repeat instructions, which are interruptible at any point. pic24f devices have sixteen, 16-bit working registers in the programmer?s model. each of the working registers can act as a data, address or address offset register. the 16 th working register (w15) operates as a software stack pointer (ssp) for interrupts and calls. the upper 32 kbytes of the data space memory map can optionally be mapped into program space at any 16k word boundary of either program memory or data eeprom memory defined by the 8-bit program space visibility page address (psvpag) register. the program to data space mapping feature lets any instruction access program space as if it were data space. the instruction set architecture (isa) has been significantly enhanced beyond that of the pic18, but maintains an acceptable level of backward compatibility. all pic18 instructions and addressing modes are supported, either directly, or through simple macros. many of the isa enhancements have been driven by compiler efficiency needs. the core supports inherent (no operand), relative, literal, memory direct and three groups of addressing modes. all modes support register direct and various register indirect modes. each group offers up to seven addressing modes. instructions are associated with predefined addressing modes depending upon their functional requirements. for most instructions, the core is capable of executing a data (or program data) memory read, a working register (data) read, a data memory write and a program (instruction) memory read per instruction cycle. as a result, three parameter instructions can be supported, allowing trinary operations (that is, a + b = c) to be executed in a single cycle. a high-speed, 17-bit by 17-bit multiplier has been included to significantly enhance the core arithmetic capability and throughput. the multiplier supports signed, unsigned and mixed mode, 16-bit by 16-bit or 8-bit by 8-bit integer multiplication. all multiply instructions execute in a single cycle. the 16-bit alu has been enhanced with integer divide assist hardware that supports an iterative non-restoring divide algorithm. it operates in conjunction with the repeat instruction looping mechanism and a selection of iterative divide instructions to support 32-bit (or 16-bit), divided by 16-bit integer signed and unsigned division. all divide operations require 19 cycles to complete but are interruptible at any cycle boundary. the pic24f has a vectored exception scheme with up to eight sources of non-maskable traps and up to 118 interrupt sources. each interrupt source can be assigned to one of seven priority levels. a block diagram of the cpu is illustrated in figure 3-1 . 3.1 programmer?s model figure 3-2 displays the programmer?s model for the pic24f. all registers in the programmer?s model are memory mapped and can be manipulated directly by instructions. table 3-1 provides a description of each register. all registers associated with the programmer?s model are memory mapped. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the cpu, refer to the ?pic24f family reference manual? , section 2. ?cpu? (ds39703).
pic24f16ka102 family ds39927c-page 24 ? 2008-2011 microchip technology inc. figure 3-1: pic24f cp u core block diagram table 3-1: cpu core registers instruction decode and control pch pcl 16 program counter 16-bit alu 23 23 24 23 data bus instruction reg 16 16 x 16 w register array divide support rom latch 16 ea mux ragu wagu 16 16 8 interrupt controller psv and table data access control block stack control logic loop control logic data latch data ram address latch control signals to various blocks program memory data latch address bus 16 literal data 16 16 hardware multiplier 16 to peripheral modules address latch data eeprom register(s) name description w0 through w15 working register array pc 23-bit program counter sr alu status register splim stack pointer limit value register tblpag table memory page address register psvpag program space visibility page address register rcount repeat loop counter register corcon cpu control register
? 2008-2011 microchip technology inc. ds39927c-page 25 pic24f16ka102 family figure 3-2: programmer?s model novz c tblpag 22 0 7 0 0 15 program counter table memory page alu status register (sr) working/address registers w0 (wreg) w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 frame pointer stack pointer psvpag 7 0 program space visibility ra 0 rcount 15 0 repeat loop counter splim stack pointer limit srl registers or bits shadowed for push.s and pop.s instructions. 0 0 page address register 15 0 cpu control register (corcon) srh w14 w15 dc ipl 210 ?? ? ? ? ? ? ipl3 psv ???????????? ?? pc divider working registers multiplier registers 15 0 value register address register register
pic24f16ka102 family ds39927c-page 26 ? 2008-2011 microchip technology inc. 3.2 cpu control registers register 3-1: sr: alu status register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0, hsc ? ? ? ? ? ? ?dc bit 15 bit 8 r/w-0, hsc ( 1 ) r/w-0, hsc ( 1 ) r/w-0, hsc ( 1 ) r-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc ipl2 ( 2 ) ipl1 ( 2 ) ipl0 ( 2 ) ra n ov z c bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 dc: alu half carry/borrow bit 1 = a carry-out from the 4 th low-order bit (for byte-sized data) or 8 th low-order bit (for word-sized data) of the result occurred 0 = no carry-out from the 4 th or 8 th low-order bit of the result has occurred bit 7-5 ipl<2:0>: cpu interrupt priority level status bits ( 1 , 2 ) 111 = cpu interrupt priority level is 7 (15); user interrupts disabled 110 = cpu interrupt priority level is 6 (14) 101 = cpu interrupt priority level is 5 (13) 100 = cpu interrupt priority level is 4 (12) 011 = cpu interrupt priority level is 3 (11) 010 = cpu interrupt priority level is 2 (10) 001 = cpu interrupt priority level is 1 (9) 000 = cpu interrupt priority level is 0 (8) bit 4 ra: repeat loop active bit 1 = repeat loop in progress 0 = repeat loop not in progress bit 3 n: alu negative bit 1 = result was negative 0 = result was non-negative (zero or positive) bit 2 ov: alu overflow bit 1 = overflow occurred for signed (2?s complement) arithmetic in this arithmetic operation 0 = no overflow has occurred bit 1 z: alu zero bit 1 = an operation, which effects the z bit, has set it at some time in the past 0 = the most recent operation, which effects the z bit, has cleared it (i.e., a non-zero result) bit 0 c: alu carry/borrow bit 1 = a carry-out from the most significant bit (msb) of the result occurred 0 = no carry-out from the most significant bit (msb) of the result occurred note 1: the ipl status bits are read-only when nstdis (intcon1<15>) = 1 . 2: the ipl status bits are concatenated with the ipl3 bit (corcon<3>) to form the cpu interrupt priority level (ipl). the value in parentheses indicates the ipl when ipl3 = 1 .
? 2008-2011 microchip technology inc. ds39927c-page 27 pic24f16ka102 family 3.3 arithmetic logic unit (alu) the pic24f alu is 16 bits wide and is capable of addition, subtraction, bit shifts and logic operations. unless otherwise mentioned, arithmetic operations are 2?s complement in nature. depending on the operation, the alu may affect the values of the carry (c), zero (z), negative (n), overflow (ov) and digit carry (dc) status bits in the sr register. the c and dc status bits operate as borrow and digit borrow bits, respectively, for subtraction operations. the alu can perform 8-bit or 16-bit operations, depending on the mode of the instruction that is used. data for the alu operation can come from the w register array, or data memory, depending on the addressing mode of the instruction. likewise, output data from the alu can be written to the w register array or a data memory location. the pic24f cpu incorporates hardware support for both multiplication and division. this includes a dedicated hardware multiplier and support hardware division for 16-bit divisor. 3.3.1 multiplier the alu contains a high-speed, 17-bit x 17-bit multiplier. it supports unsigned, signed or mixed sign operation in several multiplication modes: ? 16-bit x 16-bit signed ? 16-bit x 16-bit unsigned ? 16-bit signed x 5-bit (literal) unsigned ? 16-bit unsigned x 16-bit unsigned ? 16-bit unsigned x 5-bit (literal) unsigned ? 16-bit unsigned x 16-bit signed ? 8-bit unsigned x 8-bit unsigned register 3-2: corcon: cpu control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/c-0, hsc r/w-0 u-0 u-0 ? ? ? ?ipl3 ( 1 ) psv ? ? bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3 ipl3: cpu interrupt priority level status bit ( 1 ) 1 = cpu interrupt priority level is greater than 7 0 = cpu interrupt priority level is 7 or less bit 2 psv: program space visibility in data space enable bit 1 = program space is visible in data space 0 = program space is not visible in data space bit 1-0 unimplemented: read as ? 0 ? note 1: user interrupts are disabled when ipl3 = 1 .
pic24f16ka102 family ds39927c-page 28 ? 2008-2011 microchip technology inc. 3.3.2 divider the divide block supports 32-bit/16-bit and 16-bit/16-bit signed and unsigned integer divide operations with the following data sizes: 1. 32-bit signed/16-bit signed divide 2. 32-bit unsigned/16-bit unsigned divide 3. 16-bit signed/16-bit signed divide 4. 16-bit unsigned/16-bit unsigned divide the quotient for all divide instructions ends up in w0 and the remainder in w1. sixteen-bit signed and unsigned div instructions can specify any w register for both the 16-bit divisor (wn), and any w register (aligned) pair (w(m + 1):wm) for the 32-bit dividend. the divide algorithm takes one cycle per bit of divisor, so both 32-bit/16-bit and 16-bit/16-bit instructions take the same number of cycles to execute. 3.3.3 multi-bit shift support the pic24f alu supports both single bit and single-cycle, multi-bit arithmetic and logic shifts. multi-bit shifts are implemented using a shifter block, capable of performing up to a 15-bit arithmetic right shift, or up to a 15-bit left shift, in a single cycle. all multi-bit shift instructions only support register direct addressing for both the operand source and result destination. a full summary of instructions that use the shift operation is provided below in ta bl e 3 - 2 . table 3-2: instructions that use the si ngle and multi-bit shift operation instruction description asr arithmetic shift right source register by one or more bits. sl shift left source register by one or more bits. lsr logical shift right source register by one or more bits.
? 2008-2011 microchip technology inc. ds39927c-page 29 pic24f16ka102 family 4.0 memory organization as with harvard architecture devices, the pic24f microcontrollers feature separate program and data memory space and busing. this architecture also allows the direct access of program memory from the data space during code execution. 4.1 program address space the program address memory space of the pic24f devices is 4m instructions. the space is addressable by a 24-bit value derived from either the 23-bit program counter (pc) during program ex ecution, or from a table operation or data space remapping, as described in section 4.3 ?interfacing program and data memory spaces? . the user access to the program memory space is restricted to the lower half of the address range (000000h to 7fffffh). the exception is the use of tblrd/tblwt operations, which use tblpag<7> to permit access to the configuration bits and device id sections of the configuration memory space. memory maps for the pic24f16ka102 family of devices are displayed in figure 4-1 . figure 4-1: program space memory ma p for pic24f16ka102 family devices 000000h 0000feh 000002h 000100h f80010h f80012h fefffeh ffffffh 000004h 000200h 0001feh 000104h configuration memory space user memory space note: memory areas are not displayed to scale. reset address device config registers devid (2) goto instruction reserved alternate vector table reserved interrupt vector table pic24f16ka10x ff0000h f7fffeh f80000h 800000h 7fffffh reserved unimplemented read ? 0 ? reset address devid (2) goto instruction reserved alternate vector table reserved interrupt vector table pic24f08ka10x device config registers reserved unimplemented read ? 0 ? 0015feh 002bfe user flash program memory (5632 instructions) 7ffe00h data eeprom data eeprom flash program memory (2816 instructions)
pic24f16ka102 family ds39927c-page 30 ? 2008-2011 microchip technology inc. 4.1.1 program memory organization the program memory space is organized in word-addressable blocks. although it is treated as 24 bits wide, it is more appropriate to think of each address of the program memory as a lower and upper word, with the upper byte of the upper word being unimplemented. the lower word always has an even address, while the upper word has an odd address ( figure 4-2 ). program memory addresses are always word-aligned on the lower word, and addresses are incremented or decremented by two during code execution. this arrangement also provides compatibility with data memory space addressing and makes it possible to access data in the program memory space. 4.1.2 hard memory vectors all pic24f devices reserve the addresses between 00000h and 000200h for hard coded program execution vectors. a hardware reset vector is provided to redirect code execution from the default value of the pc on device reset to the actual start of code. a goto instruction is programmed by the user at 000000h with the actual address for the start of code at 000002h. pic24f devices also have two interrupt vector tables, located from 000004h to 0000ffh, and 000104h to 0001ffh. these vector tables allow each of the many device interrupt sources to be handled by separate isrs. section 8.1 ?interrupt vector (ivt) table? discusses the interrupt vector tables in more detail. 4.1.3 data eeprom in the pic24f16ka102 family, the data eeprom is mapped to the top of the user program memory space, starting at address, 7ffe00, and expanding up to address, 7fffff. the data eeprom is organized as 16-bit wide memory and 256 words deep. this memory is accessed using table read and write operations similar to the user code memory. 4.1.4 device configuration words table 4-1 provides the addresses of the device config- uration words for the pic24f16ka102 family. their location in the memory map is displayed in figure 4-1 . refer to section 26.1 ?configuration bits? for more information on device configuration words. table 4-1: device configuration words for pic24f16ka102 family devices figure 4-2: program memory organization configuration word configuration word addresses fbs f80000 fgs f80004 foscsel f80006 fosc f80008 fwdt f8000a fpor f8000c ficd f8000e fds f80010 0 8 16 pc address 000000h 000002h 000004h 000006h 23 00000000 00000000 00000000 00000000 program memory ?phantom? byte (read as ? 0 ?) least significant word most significant word instruction width 000001h 000003h 000005h 000007h msw address (lsw address)
? 2008-2011 microchip technology inc. ds39927c-page 31 pic24f16ka102 family 4.2 data address space the pic24f core has a separate, 16-bit wide data memory space, addressable as a single linear range. the data space is accessed using two address generation units (agus), one each for read and write operations. the data space memory map is displayed in figure 4-3 . all effective addresses (eas) in the data memory space are 16 bits wide and point to bytes within the data space. this gives a data space address range of 64 kbytes or 32k words. the lower half of the data memory space (that is, when ea<15> = 0 ) is used for implemented memory addresses, while the upper half (ea<15> = 1 ) is reserved for the program space visibility (psv) area (see section 4.3.3 ?reading data from program memory using program space visibility? ). pic24f16ka102 family devices implement a total of 768 words of data memory. should an ea point to a location outside of this area, an all zero word or byte will be returned. 4.2.1 data space width the data memory space is organized in byte-addressable, 16-bit wide blocks. data is aligned in data memory and registers as 16-bit words, but all the data space eas resolve to bytes. the least significant bytes (lsbs) of each word have even addresses, while the most significant bytes (msbs) have odd addresses. figure 4-3: data space memory map for pic24f16ka102 family devices 0000h 07feh fffeh lsb address lsb msb msb address 0001h 07ffh 0dffh ffffh 8001h 8000h 7fffh 0801h 0800h near 0dfeh sfr sfr space data ram 7fffh program space visibility area note: data memory areas are not shown to scale. 1ffeh 1fff space data space implemented data ram unimplemented read as ? 0 ?
pic24f16ka102 family ds39927c-page 32 ? 2008-2011 microchip technology inc. 4.2.2 data memory organization and alignment to maintain backward compatibility with pic ? devices and improve data space memory usage efficiency, the pic24f instruction set supports both word and byte operations. as a consequence of byte accessibility, all ea calculations are internally scaled to step through word-aligned memory. for example, the core recog- nizes that post-modified register indirect addressing mode [ws++] will result in a value of ws + 1 for byte operations and ws + 2 for word operations. data byte reads will read the complete word, which contains the byte, using the lsb of any ea to determine which byte to select. the selected byte is placed onto the lsb of the data path. that is, the data memory and the registers are organized as two parallel, byte-wide entities with shared (word) address decode, but separate write lines. data byte writes only write to the corresponding side of the array or register, which matches the byte address. all word accesses must be aligned to an even address. misaligned word data fetches are not supported, so care must be taken when mixing byte and word operations, or translating from 8-bit mcu code. if a mis- aligned read or write is attempted, an address error trap will be generated. if the error occurred on a read, the instruction underway is completed; if it occurred on a write, the instruction will be executed, but the write will not occur. in either case, a trap is then executed, allowing the system and/or user to examine the machine state prior to execution of the address fault. all byte loads into any w register are loaded into the lsb; the msb is not modified. a sign-extend instruction ( se ) is provided to allow the users to translate 8-bit signed data to 16-bit signed values. alternatively, for 16-bit unsigned data, users can clear the msb of any w register by executing a zero-extend ( ze ) instruction on the appropriate address. although most instructions are capable of operating on word or byte data sizes, it should be noted that some instructions operate only on words. 4.2.3 near data space the 8-kbyte area between 0000h and 1fffh is referred to as the near data space. locations in this space are directly addressable via a 13-bit absolute address field within all memory direct instructions. the remainder of the data space is addressable indirectly. additionally, the whole data space is addressable using mov instructions, which support memory direct addressing (mda) with a 16-bit address field. for pic24f16ka102 family devices, the entire implemented data memory lies in near data space (nds). 4.2.4 sfr space the first 2 kbytes of the near data space, from 0000h to 07ffh, are primarily occupied with special function registers (sfrs). these are used by the pic24f core and peripheral modules for controlling the operation of the device. sfrs are distributed among the modules that they control and are generally grouped together by that module. much of the sfr space contains unused addresses; these are read as ? 0 ?. the sfr space, where the sfrs are actually implemented, is provided in ta b l e 4 - 2 . each implemented area indicates a 32-byte region where at least one address is implemented as an sfr. a complete listing of implemented sfrs, including their addresses, is provided in table 4-3 through ta b l e 4 - 2 3 . table 4-2: implemented regions of sfr data space sfr space address xx00 xx20 xx40 xx60 xx80 xxa0 xxc0 xxe0 000h core icn interrupts ? 100h timers capture ?compare ? ? ? 200h i 2 c? uart spi ? ?i/o 300h a/d/cmtu ? ? ? ? ? ? 400h ? ? ? ? ? ? ? ? 500h ? ? ? ? ? ? ? ? 600h ? rtc/comp crc ? ? 700h ? ? system/ds/hlvd nvm/pmd ? ? ? ? legend: ? = no implemented sfrs in this block.
? 2008-2011 microchip technology inc. ds39927c-page 33 pic24f16ka102 family table 4-3: cpu core registers map file name addrbit 15bit 14bit 13bit 12bit 11bit 10bit 9bit 8bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 all resets wreg0 0000 working register 0 0000 wreg1 0002 working register 1 0000 wreg2 0004 working register 2 0000 wreg3 0006 working register 3 0000 wreg4 0008 working register 4 0000 wreg5 000a working register 5 0000 wreg6 000c working register 6 0000 wreg7 000e working register 7 0000 wreg8 0010 working register 8 0000 wreg9 0012 working register 9 0000 wreg10 0014 working register 10 0000 wreg11 0016 working register 11 0000 wreg12 0018 working register 12 0000 wreg13 001a working register 13 0000 wreg14 001c working register 14 0000 wreg15 001e working register 15 0800 splim 0020 stack pointer limit value register xxxx pcl 002e program counter low byte register 0000 pch 0030 ? ? ? ? ? ? ? ? program counter register high byte 0000 tblpag 0032 ? ? ? ? ? ? ? ? table memory page address register 0000 psvpag 0034 ? ? ? ? ? ? ? ? program space visibility page address register 0000 rcount 0036 repeat loop counter register xxxx sr 0042 ? ? ? ? ? ? ? dc ipl2 ipl1 ipl0 ra n ov z c 0000 corcon 0044 ? ? ? ? ? ? ? ? ? ? ? ? ipl3 psv ? ? 0000 disicnt 0052 ? ? disable interrupts counter register xxxx legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f16ka102 family ds39927c-page 34 ? 2008-2011 microchip technology inc. table 4-4: icn register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets cnen1 0060 cn15ie ( 1 ) cn14ie cn13ie cn12ie cn11ie ( 1 ) ? cn9ie cn8ie cn7ie ( 1 ) cn6ie cn5ie cn4ie cn3ie cn2ie cn1ie cn0ie 0000 cnen2 0062 ? cn30ie cn29ie ? cn27ie ( 1 ) ? ? cn24ie ( 1 ) cn23ie cn22ie cn21ie ? ? ? ?cn16ie ( 1 ) 0000 cnpu1 0068 cn15pue ( 1 ) cn14pue cn13pue cn12pue cn11pue ( 1 ) ? cn9pue cn8pue cn7pue ( 1 ) cn6pue cn5pue cn4pue cn3pue cn2pue cn1pue cn0pue 0000 cnpu2 006a ? cn30pue cn29pue ?cn27pue ( 1 ) ? ?cn24pue ( 1 ) cn23pue cn22pue cn21pue ? ? ? ? cn16pue ( 1 ) 0000 cnpd1 0070 cn15pde ( 1 ) cn14pde cn13pde cn12pde cn11pde ( 1 ) ? cn9pde cn8pde cn7pde ( 1 ) cn6pde cn5pde cn4pde cn3pde cn2pde cn1pde cn0pde 0000 cnpd2 0072 ? cn30pde cn29pde ?cn27pde ( 1 ) ? ?cn24pde ( 1 ) cn23pde cn22pde cn21pde ? ? ? ? cn16pde ( 1 ) 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are not implemented in 20-pin devices. table 4-5: interrupt controller register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets intcon1 0080 nstdis ? ? ? ? ? ? ? ? ? ? matherr addrerr stkerr oscfail ? 0000 intcon2 0082 altivt disi ? ? ? ? ? ? ? ? ? ? ? int2ep int1ep int0ep 0000 ifs0 0084 nvmif ? ad1if u1txif u1rxif spi1if spf1if t3if t2if ? ? ? t1if oc1if ic1if int0if 0000 ifs1 0086 u2txif u2rxif int2if ? ? ? ? ? ? ? ? int1if cnif cmif mi2c1if si2c1if 0000 ifs3 008a ?rtcif ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0000 ifs4 008c ? ?ctmuif ? ? ? ?hlvdif ? ? ? ? crcif u2erif u1erif ? 0000 iec0 0094 nvmie ? ad1ie u1txie u1rxie spi1ie spf1ie t3ie t2ie ? ? ? t1ie oc1ie ic1ie int0ie 0000 iec1 0096 u2txie u2rxie int2ie ? ? ? ? ? ? ? ? int1ie cnie cmie mi2c1ie si2c1ie 0000 iec3 009a ?rtcie ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0000 iec4 009c ? ?ctmuie ? ? ? ?hlvdie ? ? ? ? crcie u2erie u1erie ? 0000 ipc0 00a4 ? t1ip2 t1ip1 t1ip0 ? oc1ip2 oc1ip1 oc1ip0 ? ic1ip2 ic1ip1 ic1ip0 ? int0ip2 int0ip1 int0ip0 4444 ipc1 00a6 ? t2ip2 t2ip1 t2ip0 ? ? ? ? ? ? ? ? ? ? ? ? 4444 ipc2 00a8 ? u1rxip2 u1rxip1 u1rxip0 ? spi1ip2 spi1ip1 spi1ip0 ? spf1ip2 spf1ip1 spf1ip0 ?t3ip2t3ip1t3ip0 4444 ipc3 00aa ? nvmip2 nvmip1 nvmip0 ? ? ? ? ? ad1ip2 ad1ip1 ad1ip0 ? u1txip2 u1txip1 u1txip0 4044 ipc4 00ac ? cnip2 cnip1 cnip0 ? cmip2 cmip1 cmip0 ? mi2c1p2 mi2c1p1 mi2c1p0 ? si2c1p2 si2c1p1 si2c1p0 4444 ipc5 00ae ? ? ? ? ? ? ? ? ? ? ? ? ? int1ip2 int1ip1 int1ip0 0004 ipc7 00b2 ? u2txip2 u2txip1 u2txip0 ? u2rxip2 u2rxip1 u2rxip0 ? int2ip2 int2ip1 int2ip0 ? ? ? ? 4440 ipc15 00c2 ? ? ? ? ? rtcip2 rtcip1 rtcip0 ? ? ? ? ? ? ? ? 0400 ipc16 00c4 ? crcip2 crcip1 crcip0 ? u2erip2 u2erip1 u2erip0 ? u1erip2 u1erip1 u1erip0 ? ? ? ? 4440 ipc18 00c8 ? ? ? ? ? ? ? ? ? ? ? ? ? hlvdip2 hlvdip1 hlvdip0 0004 ipc19 00ca ? ? ? ? ? ? ? ? ? ctmuip2 ctmuip1 ctmuip0 ? ? ? ? 0040 inttreg 00e0 cpuirq ?vhold ? ilr3 ilr2 ilr1 ilr0 ? vecnum6 vecnum5 vecnum4 vecnum3 vecnum2 vecnum1 vecnum0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2008-2011 microchip technology inc. ds39927c-page 35 pic24f16ka102 family table 4-6: timer register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets tmr1 0100 timer1 register 0000 pr1 0102 timer1 period register ffff t1con 0104 ton ?tsidl ? ? ? ? ? ? tgate tckps1 tckps0 ? tsync tcs ? 0000 tmr2 0106 timer2 register 0000 tmr3hld 0108 timer3 holding register (for 32-bit timer operations only) 0000 tmr3 010a timer3 register 0000 pr2 010c timer2 period register ffff pr3 010e timer3 period register ffff t2con 0110 ton ?tsidl ? ? ? ? ? ? tgate tckps1 tckps0 t32 ?tcs ? 0000 t3con 0112 ton ?tsidl ? ? ? ? ? ? tgate tckps1 tckps0 ? ?tcs ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-7: input capture register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ic1buf 0140 input capture 1 register ffff ic1con 0142 ? ?icsidl ? ? ? ? ? ictmr ici1 ici0 icov icbne icm2 icm1 icm0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-8: output compare register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets oc1rs 0180 output compare 1 secondary register ffff oc1r 0182 output compare 1 register ffff oc1con 0184 ? ?ocsidl ? ? ? ? ? ? ? ? ocflt octsel ocm2 ocm1 ocm0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f16ka102 family ds39927c-page 36 ? 2008-2011 microchip technology inc. table 4-9: i 2 c? register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets i2c1rcv 0200 ? ? ? ? ? ? ? ? i2c1 receive register 0000 i2c1trn 0202 ? ? ? ? ? ? ? ? i2c1 transmit register 00ff i2c1brg 0204 ? ? ? ? ? ? ? i2c1 baud rate generator register 0000 i2c1con 0206 i2cen ? i2csidl sclrel ipmien a10m disslw smen gcen stren ackdt acken rcen pen rsen sen 1000 i2c1stat 0208 ackstat trstat ? ? ? bcl gcstat add10 iwcol i2cov d/a psr/w rbf tbf 0000 i2c1add 020a ? ? ? ? ? ? i2c1 address register 0000 i2c1msk 020c ? ? ? ? ? ? amsk9 amsk8 amsk7 amsk6 amsk5 amsk4 amsk3 amsk2 amsk1 amsk0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in h.5adecimal. table 4-10: uart register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets u1mode 0220 uarten ? usidl iren rtsmd ? uen1 uen0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel 0000 u1sta 0222 utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt urxisel1 urxisel0 adden ridle perr ferr oerr urxda 0110 u1txreg 0224 ? ? ? ? ? ? ? uart1 transmit register 0000 u1rxreg 0226 ? ? ? ? ? ? ? uart1 receive register 0000 u1brg 0228 baud rate generator prescaler register 0000 u2mode 0230 uarten ? usidl iren rtsmd ? uen1 uen0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel 0000 u2sta 0232 utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt urxisel1 urxisel0 adden ridle perr ferr oerr urxda 0110 u2txreg 0234 ? ? ? ? ? ? ? uart2 transmit register 0000 u2rxreg 0236 ? ? ? ? ? ? ? uart2 receive register 0000 u2brg 0238 baud rate generator prescaler 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-11: spi register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets spi1stat 0240 spien ? spisidl ? ? spibec2 spibec1 spibec0 srmpt spirov srxmpt sisel2 sisel1 sisel0 spitbf spirbf 0000 spi1con1 0242 ? ? ? dissck dissdo mode16 smp cke ssen ckp msten spre2 spre1 spre0 ppre1 ppre0 0000 spi1con2 0244 frmen spifsd spifpol ? ? ? ? ? ? ? ? ? ? ? spife spiben 0000 spi1buf 0248 spi1 transmit/receive buffer 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2008-2011 microchip technology inc. ds39927c-page 37 pic24f16ka102 family table 4-12: porta register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 ( 1 ) bit 4 bit 3 bit 2 bit 1 bit 0 all resets trisa 02c0 ? ? ? ? ? ? ? ? trisa7 ( 4 ) trisa6 ? trisa4 trisa3 ( 5 , 6 ) trisa2 ( 5 ) trisa1 trisa0 00df porta 02c2 ? ? ? ? ? ? ? ? ra7 ( 4 ) ra6 ra5 ra4 ( 3 ) ra3 ( 5 , 6 ) ra2 ( 5 ) ra1 ( 2 ) ra0 ( 2 ) xxxx lata 02c4 ? ? ? ? ? ? ? ? lata7 ( 4 ) lata6 ?lata4lata3 ( 5 , 6 ) lata2 ( 5 ) lata1 lata0 xxxx odca 02c6 ? ? ? ? ? ? ? ? oda7 ( 4 ) oda6 ? oda4 oda3 ( 5 , 6 ) oda2 ( 5 ) oda1 oda0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: this bit is available only when mclre = 0 . 2: a read of ra1 and ra0 results in ? 0 ? when debug is active on the pgc2/pgd2 pin. 3: a read of ra4 results in ? 0 ? when debug is active on the pgc3/pgd3 pin. 4: these bits are not implemented in 20-pin devices. 5: these bits are available only when the primary oscillator is disabled (poscmd<1:0> = 00 ); otherwise read as ? 0 ?. 6: these bits are available only when the primary oscillator is disabled or ec mode is selected (poscmd<1:0> = 00 or 11 ) and clko is disabled (osciofnc = 0 ); otherwise read as ? 0 ?. table 4-13: portb register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets trisb 02c8 trisb15 trisb14 trisb13 trisb12 trisb11 ( 3 ) trisb10 ( 3 ) trisb9 trisb8 trisb7 trisb6 ( 3 ) trisb5 ( 3 ) trisb4 trisb3 ( 3 ) trisb2 trisb1 trisb0 ffff portb 02ca rb15 rb14 rb13 rb12 rb11 ( 3 ) rb10 ( 3 ) rb9 rb8 rb7 rb6 ( 3 ) rb5 ( 3 ) rb4 ( 2 ) rb3 ( 3 ) rb2 rb1 ( 1 ) rb0 ( 1 ) xxxx latb 02cc latb15 latb14 latb13 latb12 latb11 ( 3 ) latb10 ( 3 ) latb9 latb8 latb7 latb6 ( 3 ) latb5 ( 3 ) latb4 latb3 ( 3 ) latb2 latb1 latb0 xxxx odcb 02ce odb15 odb14 odb13 odb12 odb11 odb10 odb9 odb8 odb7 odb6 odb5 odb4 odb3 odb2 odb1 odb0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: a read of rb1 and rb0 results in ? 0 ? when debug is active on the pgec1/pged1 pins. 2: a read of rb4 results in ? 0 ? when debug is active on the pgec3/pged3 pins. 3: portb bits, 11, 10, 6, 5 and 3, are not implemented in 20-pin devices. table 4-14: pad config uration register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets padcfg1 02fc ? ? ? ? ? ? ? ? ? ? ? smbusdel oc1tris rtsecsel1 rtsecsel0 ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f16ka102 family ds39927c-page 38 ? 2008-2011 microchip technology inc. table 4-15: a/d register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets adc1buf0 0300 a/d data buffer 0 xxxx adc1buf1 0302 a/d data buffer 1 xxxx adc1buf2 0304 a/d data buffer 2 xxxx adc1buf3 0306 a/d data buffer 3 xxxx adc1buf4 0308 a/d data buffer 4 xxxx adc1buf5 030a a/d data buffer 5 xxxx adc1buf6 030c a/d data buffer 6 xxxx adc1buf7 030e a/d data buffer 7 xxxx adc1buf8 0310 a/d data buffer 8 xxxx adc1buf9 0312 a/d data buffer 9 xxxx adc1bufa 0314 a/d data buffer 10 xxxx adc1bufb 0316 a/d data buffer 11 xxxx adc1bufc 0318 a/d data buffer 12 xxxx adc1bufd 031a a/d data buffer 13 xxxx adc1bufe 031c a/d data buffer 14 xxxx adc1buff 031e a/d data buffer 15 xxxx ad1con1 0320 adon ?adsidl ? ? ? form1 form0 ssrc2 ssrc1 ssrc0 ? ? asam samp done 0000 ad1con2 0322 vcfg2 vcfg1 vcfg0 offcal ?cscna ? ?bufs ? smpi3 smpi2 smpi1 smpi0 bufm alts 0000 ad1con3 0324 adrc ? ? samc4 samc3 samc2 samc1 samc0 ? ? adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 0000 ad1chs 0328 ch0nb ? ? ? ch0sb3 ch0sb2 ch0sb1 ch0sb0 ch0na ? ? ch0sa4 ch0sa3 ch0sa2 ch0sa1 ch0sa0 0000 ad1pcfg 032c ? ? ? pcfg12 pcfg11 pcfg10 ? ? ? ? pcfg5 pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 0000 ad1cssl 0330 ? ? ? cssl12 cssl11 cssl10 ? ? ? ? cssl5 cssl4 cssl3 cssl2 cssl1 cssl0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-16: ctmu register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ctmucon 033c ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig edg2pol edg2sel1 edg2sel0 edg1pol edg1sel1 edg1sel0 edg2stat edg1stat 0000 ctmuicon 033e itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 ? ? ? ? ? ? ? ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2008-2011 microchip technology inc. ds39927c-page 39 pic24f16ka102 family table 4-17: real-time clock and calendar register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets alrmval 0620 alarm value register window based on alrmptr<15:0> xxxx alcfgrpt 0622 alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 0000 rtcval 0624 rtcc value register window based on rtcptr<15:0> xxxx rcfgcal 0626 rtcen ? rtcwren rtcsync halfsec rtcoe rtcptr1 rtcptr0 cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-18: dual comparator register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets cmstat 0630 cmsidl ? ? ? ? ? c2evt c1evt ? ? ? ? ? ? c2out c1out 0000 cvrcon 0632 ? ? ? ? ? ? ? ? cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 cm1con 0634 con coe cpol clpwr ? ? cevt cout evpol1 evpol0 ?cref ? ? cch1 cch0 0000 cm2con 0636 con coe cpol clpwr ? ? cevt cout evpol1 evpol0 ?cref ? ? cch1 cch0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-19: crc register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets crccon 0640 ? ? csidl vword4 vword3 vword2 vword1 vword0 crcful crcmpt ? crcgo plen3 plen2 plen1 plen0 0040 crcxor 0642 x<15:1> ? 0000 crcdat 0644 crc data input register 0000 crcwdat 0646 crc result register 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f16ka102 family ds39927c-page 40 ? 2008-2011 microchip technology inc. table 4-20: clock control register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets rcon 0740 trapr iopuwr sboren ? ? dpslp ? pmslp extr swr swdten wdto sleep idle bor por (note 1 ) osccon 0742 ? cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 clklock ? lock ?cf ? soscen oswen (note 2 ) clkdiv 0744 roi doze2 doze1 doze0 dozen rcdiv2 rcdiv1 rcdiv0 ? ? ? ? ? ? ? ? 3140 osctun 0748 ? ? ? ? ? ? ? ? ? ? tun5 tun4 tun3 tun2 tun1 tun0 0000 refocon 074e roen ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 ? ? ? ? ? ? ? ? 0000 hlvdcon 0756 hlvden ?hlsidl ? ? ? ? ? vdir bgvst irvst ? hlvdl3 hlvdl2 hlvdl1 hlvdl0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: rcon register reset values are dependent on the type of reset. 2: osccon register reset values are dependent on configuration fuses and by type of reset. table 4-21: deep sleep register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ( 1 ) dscon 0758 dsen ? ? ? ? ? ? ? ? ? ? ? ? ? dsbor release 0000 dswake 075a ? ? ? ? ? ? ?dsint0dsflt ? ? dswdt dsrtcc dsmclr ? dspor 0000 dsgpr0 075c deep sleep general purpose register 0 0000 dsgpr1 075e deep sleep general purpose register 1 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: the deep sleep registers are only reset on a v dd por event. table 4-22: nvm register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets nvmcon 0760 wr wren wrerr pgmonly ? ? ? ? ? erase nvmop5 nvmop4 nvmop3 nvmop2 nvmop1 nvmop0 0000 ( 1 ) nvmkey 0766 ? ? ? ? ? ? ? ? nvmkey7 nvmkey6 nvmkey5 nvmkey4 nvmkey3 nvmkey2 nvmkey1 nvmkey0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: reset value shown is for por only. value on other reset states is dependent on the state of memory write or erase operations at the time of reset. table 4-23: pmd register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets pmd1 0770 ? ? t3md t2md t1md ? ? ? i2c1md u2md u1md ? spi1md ? ?adc1md 0000 pmd2 0772 ? ? ? ? ? ? ?ic1md ? ? ? ? ? ? ?oc1md 0000 pmd3 0774 ? ? ? ? ? cmpmd rtccmd ?crcpmd ? ? ? ? ? ? ? 0000 pmd4 0776 ? ? ? ? ? ? ? ? ? ? ? eemd refomd ctmumd hlvdmd ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2008-2011 microchip technology inc. ds39927c-page 41 pic24f16ka102 family 4.2.5 software stack in addition to its use as a working register, the w15 register in pic24f devices is also used as a software stack pointer. the pointer always points to the first available free word and grows from lower to higher addresses. it pre-decrements for stack pops and post-increments for stack pushes, as depicted in figure 4-4 . for a pc push during any call instruction, the msb of the pc is zero-extended before the push, ensuring that the msb is always clear. the stack pointer limit value (splim) register, associated with the stack pointer, sets an upper address boundary for the stack. splim is uninitialized at reset. as is the case for the stack pointer, splim<0> is forced to ? 0 ? as all stack operations must be word-aligned. whenever an ea is generated using w15 as a source or destination pointer, the resulting address is compared with the value in splim. if the contents of the stack pointer (w15) and the splim register are equal, and a push operation is performed, a stack error trap will not occur. the stack error trap will occur on a subsequent push operation. thus, for example, if it is desirable to cause a stack error trap when the stack grows beyond address, 0df6 in ram, initialize the splim with the value, 0df4. similarly, a stack pointer underflow (stack error) trap is generated when the stack pointer address is found to be less than 0800h. this prevents the stack from interfering with the special function register (sfr) space. figure 4-4: call stack frame 4.3 interfacing program and data memory spaces the pic24f architecture uses a 24-bit wide program space and 16-bit wide data space. the architecture is also a modified harvard scheme, meaning that data can also be present in the program space. to use this data successfully, it must be accessed in a way that preserves the alignment of information in both spaces. apart from the normal execution, the pic24f architecture provides two methods by which the program space can be accessed during operation: ? using table instructions to access individual bytes or words anywhere in the program space ? remapping a portion of the program space into the data space, psv table instructions allow an application to read or write small areas of the program memory. this makes the method ideal for accessing data tables that need to be updated from time to time. it also allows access to all bytes of the program word. the remapping method allows an application to access a large block of data on a read-only basis, which is ideal for look ups from a large table of static data. it can only access the least significant word (lsw) of the program word. 4.3.1 addressing program space since the address ranges for the data and program spaces are 16 and 24 bits, respectively, a method is needed to create a 23-bit or 24-bit program address from 16-bit data registers. the solution depends on the interface method to be used. for table operations, the 8-bit table memory page address register (tblpag) is used to define a 32k word region within the program space. this is concatenated with a 16-bit ea to arrive at a full 24-bit program space address. in this format, the most significant bit (msb) of tblpag is used to determine if the operation occurs in the user memory (tblpag<7> = 0 ) or the configuration memory (tblpag<7> = 1 ). for remapping operations, the 8-bit program space visibility page address register (psvpag) is used to define a 16k word page in the program space. when the msb of the ea is ? 1 ?, psvpag is concatenated with the lower 15 bits of the ea to form a 23-bit program space address. unlike the table operations, this limits remapping operations strictly to the user memory area. see tab l e 4 - 24 and figure 4-5 to know how the program ea is created for table operations and remapping accesses from the data ea. here, p<23:0> refers to a program space word, whereas d<15:0> refers to a data space word. note: a pc push during exception processing will concatenate the srl register to the msb of the pc prior to the push. note: a write to the splim register should not be immediately followed by an indirect read operation using w15. pc<15:0> 000000000 0 15 w15 (before call) w15 (after call) stack grows towards higher address 0000h pc<22:16> pop : [--w15] push : [w15++]
pic24f16ka102 family ds39927c-page 42 ? 2008-2011 microchip technology inc. table 4-24: program space address construction figure 4-5: data access from program space address generation access type access space program space address <23> <22:16> <15> <14:1> <0> instruction access (code execution) user 0 pc<22:1> 0 0xx xxxx xxxx xxxx xxxx xxx0 tblrd/tblwt (byte/word read/write) user tblpag<7:0> data ea<15:0> 0xxx xxxx xxxx xxxx xxxx xxxx configuration tblpag<7:0> data ea<15:0> 1xxx xxxx xxxx xxxx xxxx xxxx program space visibility (block remap/read) user 0 psvpag<7:0> ( 2 ) data ea<14:0> ( 1 ) 0 xxxx xxxx xxx xxxx xxxx xxxx note 1: data ea<15> is always ? 1 ? in this case, but is not used in calculating the program space address. bit 15 of the address is psvpag<0>. 2: psvpag can have only two values (? 00 ? to access program memory and ff to access data eeprom) on the pic24f16ka102 family. 0 program counter 23 bits 1 psvpag 8 bits ea 15 bits program counter (1) select tblpag 8 bits ea 16 bits byte select 0 0 1/0 user/configuration table operations (2) program space visibility (1) space select 24 bits 23 bits (remapping) 1/0 0 note 1: the lsb of program space addres ses is always fixed as ? 0 ? in order to maintain word alignment of data in the program and data spaces. 2: table operations are not required to be word-aligned. t able read operations are permi tted in the configuration memory space.
? 2008-2011 microchip technology inc. ds39927c-page 43 pic24f16ka102 family 4.3.2 data access from program memory and data eeprom memory using table instructions the tblrdl and tblwtl instructions offer a direct method of reading or writing the lower word of any address within the program memory without going through data space. it also offers a direct method of reading or writing a word of any address within data eeprom memory. the tblrdh and tblwth instruc- tions are the only method to read or write the upper 8 bits of a program space word as data. the pc is incremented by 2 for each successive 24-bit program word. this allows program memory addresses to directly map to data space addresses. program memory can thus be regarded as two 16-bit, word-wide address spaces, residing side by side, each with the same address range. tblrdl and tblwtl access the space which contains the least significant data word, and tblrdh and tblwth access the space which contains the upper data byte. two table instructions are provided to move byte or word-sized (16-bit) data to and from program space. both function as either byte or word operations. 1. tblrdl (table read low): in word mode, it maps the lower word of the program space location (p<15:0>) to a data address (d<15:0>). in byte mode, either the upper or lower byte of the lower program word is mapped to the lower byte of a data address. the upper byte is selected when byte select is ? 1 ?; the lower byte is selected when it is ? 0 ?. 2. tblrdh (table read high): in word mode, it maps the entire upper word of a program address (p<23:16>) to a data address. note that d<15:8>, the ?phantom? byte, will always be ? 0 ?. in byte mode, it maps the upper or lower byte of the program word to d<7:0> of the data address, as above. note that the data will always be ? 0 ? when the upper ?phantom? byte is selected (byte select = 1 ). in a similar fashion, two table instructions, tblwth and tblwtl , are used to write individual bytes or words to a program space address. the details of their operation are explained in section 5.0 ?flash program memory? . for all table operations, the area of program memory space to be accessed is determined by the table memory page address register (tblpag). tblpag covers the entire program memory space of the device, including user and configuration spaces. when tblpag<7> = 0 , the table page is located in the user memory space. when tblpag<7> = 1 , the page is located in configuration space. figure 4-6: accessing program memory with table instructions note: the tblrdh and tblwth instructions are not used while accessing data eeprom memory. note: only table read operations will execute in the configuration memory space, and only then, in implemented areas, such as the device id. table write operations are not allowed. 0 8 16 23 00000000 00000000 00000000 00000000 ?phantom? byte tblrdh.b (wn<0> = 0 ) tblrdl.w tblrdl.b (wn<0> = 1 ) tblrdl.b (wn<0> = 0 ) 23 15 0 tblpag 00 000000h 800000h 002bfeh program space data ea<15:0> the address for the table operation is determined by the data ea within the page defined by the tblpag register. only read operations are provided; write op erations are also valid in the user memory area.
pic24f16ka102 family ds39927c-page 44 ? 2008-2011 microchip technology inc. 4.3.3 reading data from program memory using program space visibility the upper 32 kbytes of data space may optionally be mapped into an 8k word page (in pic24f08ka1xx devices) and a 16k word page (in pic24f16ka1xx devices) of the program space. this provides transparent access of stored constant data from the data space without the need to use special instructions (i.e., tblrdl/h ). program space access through the data space occurs if the msb of the data space, ea, is ? 1 ?, and psv is enabled by setting the psv bit in the cpu control (corcon<2>) register. the location of the program memory space to be mapped into the data space is determined by the program space visibility page address register (psvpag). this 8-bit register defines any one of 256 possible pages of 16k words in pro- gram space. in effect, psvpag functions as the upper 8 bits of the program memory address, with the 15 bits of the ea functioning as the lower bits. by incrementing the pc by 2 for each program memory word, the lower 15 bits of data space addresses directly map to the lower 15 bits in the corresponding program space addresses. data reads from this area add an additional cycle to the instruction being executed, since two program memory fetches are required. although each data space address, 8000h and higher, maps directly into a corresponding program memory address (see figure 4-7 ), only the lower 16 bits of the 24-bit program word are used to contain the data. the upper 8 bits of any program space locations used as data should be programmed with ? 1111 1111 ? or ? 0000 0000 ? to force a nop . this prevents possible issues should the area of code ever be accidentally executed. for operations that use psv and are executed outside a repeat loop, the mov and mov.d instructions will require one instruction cycle in addition to the specified execution time. all other instructions will require two instruction cycles in addition to the specified execution time. for operations that use psv, which are executed inside a repeat loop, there will be some instances that require two instruction cycles in addition to the specified execution time of the instruction: ? execution in the first iteration ? execution in the last iteration ? execution prior to exiting the loop due to an interrupt ? execution upon re-entering the loop after an interrupt is serviced any other iteration of the repeat loop will allow the instruction accessing data, using psv, to execute in a single cycle. figure 4-7: program spac e visibility operation note: psv access is temporarily disabled during table reads/writes. 23 15 0 psvpag data space program space 0000h 8000h ffffh 00 000000h 800000h 002bfeh when corcon<2> = 1 and ea<15> = 1 : psv area the data in the page designated by psvpag is mapped into the upper half of the data memory space.... data ea<14:0> ...while the lower 15 bits of the ea specify an exact address within the psv area. this corresponds exactly to the same lower 15 bits of the actual program space address.
? 2008-2011 microchip technology inc. ds39927c-page 45 pic24f16ka102 family 5.0 flash program memory the pic24fj64ga family of devices contains internal flash program memory for storing and executing appli- cation code. the memory is readable, writable and erasable when operating with v dd over 1.8v. flash memory can be programmed in three ways: ? in-circuit serial programming? (icsp?) ? run-time self-programming (rtsp) ? enhanced in-circuit serial programming (enhanced icsp) icsp allows a pic24f16ka102 device to be serially programmed while in the end application circuit. this is simply done with two lines for the programming clock and programming data (which are named pgcx and pgdx, respectively), and three other lines for power (v dd ), ground (v ss ) and master clear/program mode entry voltage (mclr /v pp ). this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or custom firmware to be programmed. real-time self-programming (rtsp) is accomplished using tblrd (table read) and tblwt (table write) instructions. with rtsp, the user may write program memory data in blocks of 32 instructions (96 bytes) at a time, and erase program memory in blocks of 32, 64 and 128 instructions (96,192 and 384 bytes) at a time. the nvmop<1:0> (nvmcon<1:0>) bits decide the erase block size. 5.1 table instructions and flash programming regardless of the method used, flash memory programming is done with the table read and write instructions. these allow direct read and write access to the program memory space from the data memory while the device is in normal operating mode. the 24-bit target address in the program memory is formed using the tblpag<7:0> bits and the effective address (ea) from a w register, specified in the table instruction, as depicted in figure 5-1 . the tblrdl and the tblwtl instructions are used to read or write to bits<15:0> of program memory. tblrdl and tblwtl can access program memory in both word and byte modes. the tblrdh and tblwth instructions are used to read or write to bits<23:16> of program memory. tblrdh and tblwth can also access program memory in word or byte mode. figure 5-1: addressing for table registers note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on flash pro- gramming, refer to the ?pic24f family reference manual? , section 4. ?program memory? (ds39715). 24 bits program tblpag reg 8 bits 16 bits using byte 24-bit ea 1/0 select table instruction counter using user/configuration space select working reg ea 0 program counter 0
pic24f16ka102 family ds39927c-page 46 ? 2008-2011 microchip technology inc. 5.2 rtsp operation the pic24f flash program memory array is organized into rows of 32 instructions or 96 bytes. rtsp allows the user to erase blocks of 1 row, 2 rows and 4 rows (32, 64 and 128 instructions) at a time and to program one row at a time. it is also possible to program single words. the 1-row (96 bytes), 2-row (192 bytes) and 4-row (384 bytes) erase blocks, and single row write block (96 bytes) are edge-aligned, from the beginning of program memory. when data is written to program memory using tblwt instructions, the data is not written directly to memory. instead, data written using table writes is stored in holding latches until the programming sequence is executed. any number of tblwt instructions can be executed and a write will be successfully performed. however, 32 tblwt instructions are required to write the full row of memory. the basic sequence for rtsp programming is to set up a table pointer, then do a series of tblwt instructions to load the buffers. programming is performed by setting the control bits in the nvmcon register. data can be loaded in any order and the holding registers can be written to multiple times before performing a write operation. subsequent writes, however, will wipe out any previous writes. all of the table write operations are single-word writes (two instruction cycles), because only the buffers are written. a programming cycle is required for programming each row. 5.3 enhanced in-circuit serial programming enhanced icsp uses an on-board bootloader, known as the program executive, to manage the programming process. using an spi data frame format, the program executive can erase, program and verify program memory. for more information on enhanced icsp, see the device programming specification. 5.4 control registers there are two sfrs used to read and write the program flash memory: nvmcon and nvmkey. the nvmcon register ( register 5-1 ) controls the blocks that need to be erased, which memory type is to be programmed and when the programming cycle starts. nvmkey is a write-only register that is used for write protection. to start a pr ogramming or erase sequence, the user must consecutively write 55h and aah to the nvmkey register. refer to section 5.5 ?programming operations? for further details. 5.5 programming operations a complete programming sequence is necessary for programming or erasing the internal flash in rtsp mode. during a programming or erase operation, the processor stalls (waits) until the operation is finished. setting the wr bit (nvmcon<15>) starts the operation and the wr bit is automatically cleared when the operation is finished. note: writing to a location multiple times without erasing it is not recommended.
? 2008-2011 microchip technology inc. ds39927c-page 47 pic24f16ka102 family register 5-1: nvmcon: flash memory control register r/so-0, hc r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 wr wren wrerr pgmonly ( 4 ) ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? erase nvmop5 ( 1 ) nvmop4 ( 1 ) nvmop3 ( 1 ) nvmop2 ( 1 ) nvmop1 ( 1 ) nvmop0 ( 1 ) bit 7 bit 0 legend: so = settable only bit hc = hardware clearable bit -n = value at por ?1? = bit is set r = readable bit w = writable bit ?0? = bit is cleared x = bit is unknown u = unimplemented bit, read as ?0? bit 15 wr: write control bit 1 = initiates a flash memory program or erase operation. the operation is self-timed and the bit is cleared by hardware once the operation is complete 0 = program or erase operation is complete and inactive bit 14 wren: write enable bit 1 = enable flash program/erase operations 0 = inhibit flash program/erase operations bit 13 wrerr: write sequence error flag bit 1 = an improper program or erase sequence attempt or termination has occurred (bit is set automatically on any set attempt of the wr bit) 0 = the program or erase operation completed normally bit 12 pgmonly: program only enable bit ( 4 ) bit 11-7 unimplemented: read as ? 0 ? bit 6 erase: erase/program enable bit 1 = perform the erase operation specified by nvmop<5:0> on the next wr command 0 = perform the program operation specified by nvmop<5:0> on the next wr command bit 5-0 nvmop<5:0>: programming operation command byte bits ( 1 ) erase operations (when erase bit is ? 1 ?): 1010xx = erase entire boot block (including code-protected boot block) ( 2 ) 1001xx = erase entire memory (including boot block, configuration block, general block) ( 2 ) 011010 = erase 4 rows of flash memory ( 3 ) 011001 = erase 2 rows of flash memory ( 3 ) 011000 = erase 1 row of flash memory ( 3 ) 0101xx = erase entire configuration block (except code protection bits) 0100xx = erase entire data eeprom ( 4 ) 0011xx = erase entire general memory block programming operations 0001xx = write 1 row of flash memory (when erase bit is ? 0 ?) ( 3 ) note 1: all other combinations of nvmop<5:0> are no operation. 2: available in icsp? mode only. refer to device programming specification. 3: the address in the table pointer decides which rows will be erased. 4: this bit is used only while accessing data eeprom.
pic24f16ka102 family ds39927c-page 48 ? 2008-2011 microchip technology inc. 5.5.1 programming algorithm for flash program memory the user can program one row of flash program memory at a time by erasing the programmable row. the general process is: 1. read a row of program memory (32 instructions) and store in data ram. 2. update the program data in ram with the desired new data. 3. erase a row (see example 5-1 ): a) set the nvmop bits (nvmcon<5:0>) to ? 011000 ? to configure for row erase. set the erase (nvmcon<6>) and wren (nvmcon<14>) bits. b) write the starting address of the block to be erased into the tblpag and w registers. c) write 55h to nvmkey. d) write aah to nvmkey. e) set the wr bit (nvmcon<15>). the erase cycle begins and the cpu stalls for the duration of the erase cycle. when the erase is done, the wr bit is cleared automatically. 4. write the first 32 instructions from data ram into the program memory buffers (see example 5-1 ). 5. write the program block to flash memory: a) set the nvmop bits to ? 000100 ? to configure for row programming. clear the erase bit and set the wren bit. b) write 55h to nvmkey. c) write aah to nvmkey. d) set the wr bit. the programming cycle begins and the cpu stalls for the duration of the write cycle. when the write to flash memory is done, the wr bit is cleared automatically. for protection against accidental operations, the write initiate sequence for nvmkey must be used to allow any erase or program operation to proceed. after the programming command has been executed, the user must wait for the programming time until programming is complete. the two instructions following the start of the programming sequence should be nop s, as displayed in example 5-5 . example 5-1: erasing a program memo ry row ? assembly language code example 5-2: erasing a program me mory row ? ?c? language code ; set up nvmcon for row erase operation mov #0x4058, w0 ; mov w0, nvmcon ; initialize nvmcon ; init pointer to row to be erased mov #tblpage(prog_addr), w0 ; mov w0, tblpag ; initialize pm page boundary sfr mov #tbloffset(prog_addr), w0 ; initialize in-page ea[15:0] pointer tblwtl w0, [w0] ; set base address of erase block disi #5 ; block all interrupts for next 5 instructions mov #0x55, w0 mov w0, nvmkey ; write the 55 key mov #0xaa, w1 ; mov w1, nvmkey ; write the aa key bset nvmcon, #wr ; start the erase sequence nop ; insert two nops after the erase nop ; command is asserted // c example using mplab c30 int __attribute__ ((space(auto_psv))) progaddr = 0x1234; // variable located in pgm memory, declared as a // global variable unsigned int offset; //set up pointer to the first memory location to be written tblpag = __builtin_tblpage(&progaddr); // initialize pm page boundary sfr offset = __ builtin_tbloffset(&progaddr); // initialize lower word of address __builtin_tblwtl(offset, 0x0000); // set base address of erase block // with dummy latch write nvmcon = 0x4058; // initialize nvmcon asm("disi #5"); // block all interrupts for next 5 instructions __builtin_write_nvm(); // c30 function to perform unlock // sequence and set wr
? 2008-2011 microchip technology inc. ds39927c-page 49 pic24f16ka102 family example 5-3: loading the write bu ffers ? assembly language code example 5-4: loading the write buffers ? ?c? language code ; set up nvmcon for row programming operations mov #0x4004, w0 ; mov w0, nvmcon ; initialize nvmcon ; set up a pointer to the first program memory location to be written ; program memory selected, and writes enabled mov #0x0000, w0 ; mov w0, tblpag ; initialize pm page boundary sfr mov #0x1500, w0 ; an example program memory address ; perform the tblwt instructions to write the latches ; 0th_program_word mov #low_word_0, w2 ; mov #high_byte_0, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; 1st_program_word mov #low_word_1, w2 ; mov #high_byte_1, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; 2nd_program_word mov #low_word_2, w2 ; mov #high_byte_2, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ? ? ? ; 32nd_program_word mov #low_word_31, w2 ; mov #high_byte_31, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0] ; write pm high byte into program latch // c example using mplab c30 #define num_instruction_per_row 64 int __attribute__ ((space(auto_psv))) progaddr = 0x1234 // variable located in pgm memory unsigned int offset; unsigned int i; unsigned int progdata[2*num_instruction_per_row]; // buffer of data to write //set up nvmcon for row programming nvmcon = 0x4004; // initialize nvmcon //set up pointer to the first memory location to be written tblpag = __builtin_tblpage(&progaddr); // initialize pm page boundary sfr offset = __ builtin_tbloffset(&progaddr); // initialize lower word of address //perform tblwt instructions to write necessary number of latches for(i=0; i < 2*num_instruction_per_row; i++) { __builtin_tblwtl(offset, progdata[i++]); // write to address low word __builtin_tblwth(offset, progdata[i]); // write to upper byte offset = offset + 2; // increment address }
pic24f16ka102 family ds39927c-page 50 ? 2008-2011 microchip technology inc. example 5-5: initiating a programming sequence ? assembly language code example 5-6: initiating a programmi ng sequence ? ?c? language code disi #5 ; block all interrupts for next 5 instructions mov #0x55, w0 mov w0, nvmkey ; write the 55 key mov #0xaa, w1 ; mov w1, nvmkey ; write the aa key bset nvmcon, #wr ; start the erase sequence nop ; 2 nops required after setting wr nop ; btsc nvmcon, #15 ; wait for the sequence to be completed bra $-2 ; // c example using mplab c30 asm("disi #5"); // block all interrupts for next 5 instructions __builtin_write_nvm(); // perform unlock sequence and set wr
? 2008-2011 microchip technology inc. ds39927c-page 51 pic24f16ka102 family 6.0 data eeprom memory the data eeprom memory is a nonvolatile memory (nvm), separate from the program and volatile data ram. data eeprom memory is based on the same flash technology as program memory, and is optimized for both long retention and a higher number of erase/write cycles. the data eeprom is mapped to the top of the user program memory space, with the top address at program memory address, 7ffe00h to 7fffffh. the size of the data eeprom is 256 words in pic24f16ka102 devices. the data eeprom is organized as 16-bit wide memory. each word is directly addressable, and is readable and writable during normal operation over the entire v dd range. unlike the flash program memory, normal program execution is not stopped during a data eeprom program or erase operation. the data eeprom programming operations are controlled using the three nvm control registers: ? nvmcon: nonvolatile memory control register ? nvmkey: nonvolatile memory key register ? nvmadr: nonvolatile memory address register 6.1 nvmcon register the nvmcon register ( register 6-1 ) is also the pri- mary control register for data eeprom program/erase operations. the upper byte contains the control bits used to start the program or erase cycle, and the flag bit to indicate if the operation was successfully performed. the lower byte of nvmcom configures the type of nvm operation that will be performed. 6.2 nvmkey register the nvmkey is a write-only register that is used to prevent accidental writes or erasures of data eeprom locations. to start any programming or erase sequence, the following instructions must be executed first, in the exact order provided: 1. write 55h to nvmkey. 2. write aah to nvmkey. after this sequence, a write will be allowed to the nvmcon register for one instruction cycle. in most cases, the user will simply need to set the wr bit in the nvmcon register to start the program or erase cycle. interrupts should be disabled during the unlock sequence. the mplab ? c30 c compiler provides a defined library procedure ( builtin_write_nvm ) to perform the unlock sequence. example 6-1 illustrates how the unlock sequence can be performed with in-line assembly. example 6-1: data eeprom unlock sequence note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on data eeprom, refer to the ?pic24f family reference manual? , section 5. ?data eeprom? (ds39720). //disable interrupts for 5 instructions asm volatile ("disi #5"); //issue unlock sequence asm volatile ("mov #0x55, w0 \n" " mov w0, nvmkey \n" "mov #0xaa, w1 \n" "mov w1, nvmkey \n"); // perform write/erase operations asm volatile ("bset nvmcon, #wr \n" "nop \n" "nop \n");
pic24f16ka102 family ds39927c-page 52 ? 2008-2011 microchip technology inc. register 6-1: nvmcon: nonvolat ile memory control register r/s-0, hc r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 wr wren wrerr pgmonly ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? erase nvmop5 nvmop4 nvmop3 nvmop2 nvmop1 nvmop0 bit 7 bit 0 legend: u = unimplemented bit, read as ?0? r = readable bit w = writable bit s = settable bit hc = hardware clearable bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 wr: write control bit (program or erase) 1 = initiates a data eeprom erase or write cycle (can be set but not cleared in software) 0 = write cycle is complete (cleared automatically by hardware) bit 14 wren: write enable bit (erase or program) 1 = enable an erase or program operation 0 = no operation allowed (device clears this bit on completion of the write/erase operation) bit 13 wrerr: flash error flag bit 1 = a write operation is prematurely terminated (any mclr or wdt reset during programming operation) 0 = the write operation completed successfully bit 12 pgmonly: program only enable bit 1 = write operation is executed without erasing target address(es) first 0 = automatic erase-before-write: write operations are preceded automatically by an erase of target address(es) bit 11-7 unimplemented: read as ? 0 ? bit 6 erase: erase operation select bit 1 = perform an erase operation when wr is set 0 = perform a write operation when wr is set bit 5-0 nvmop<5:0>: programming operation command byte bits erase operations (when erase bit is ? 1 ?): 011010 = erase 8 words 011001 = erase 4 words 011000 = erase 1 word 0100xx = erase entire data eeprom programming operations (when erase bit is ? 0 ?): 001xx = write 1 word
? 2008-2011 microchip technology inc. ds39927c-page 53 pic24f16ka102 family 6.3 nvm address register as with flash program memory, the nvm address registers, nvmadru and nvmadr, form the 24-bit effective address (ea) of the selected row or word for data eeprom operations. the nvmadru register is used to hold the upper 8 bits of the ea, while the nvmadr register is used to hold the lower 16 bits of the ea. these registers are not mapped into the special function register (sfr) space; instead, they directly capture the ea<23:0> of the last table write instruction that has been executed and selects the data eeprom row to erase. figure 6-1 depicts the program memory ea that is formed for programming and erase operations. like program memory operations, the least significant bit (lsb) of nvmadr is restricted to even addresses. this is because any given address in the data eeprom space consists of only the lower word of the program memory width; the upper word, including the uppermost ?phantom byte?, are unavailable. this means that the lsb of a data eeprom address will always be ? 0 ?. similarly, the most significant bit (msb) of nvmadru is always ? 0 ?, since all addresses lie in the user program space. figure 6-1: data eeprom addressing with tblpag and nvm address registers 6.4 data eeprom operations the eeprom block is accessed using table read and write operations, similar to those used for program memory. the tblwth and tblrdh instructions are not required for data eeprom operations, since the memory is only 16 bits wide (data on the lower address is valid only). the following programming operations can be performed on the data eeprom: ? erase one, four or eight words ? bulk erase the entire data eeprom ? write one word ? read one word the library procedures are used in the code examples detailed in the following sections. general descriptions of each process are provided for users who are not using the c30 compiler libraries. 24-bit pm address tblpag nvmadr w register ea 7fh xxxxh 0 0 nvmadru note 1: unexpected results will be obtained should the user attempt to read the eeprom while a programming or erase operation is underway. 2: the c30 c compiler includes library procedures to automatically perform the table read and table write operations, manage the table pointer and write buffers, and unlock and initiate memory write sequences. this eliminates the need to create assembler macros or time critical routines in c for each application.
pic24f16ka102 family ds39927c-page 54 ? 2008-2011 microchip technology inc. 6.4.1 erase data eeprom the data eeprom can be fully erased, or can be partially erased, at three different sizes: one word, four words or eight words. the bits, nvmop<1:0> (nvmcon<1:0>), decide the number of words to be erased. to erase partially from the data eeprom, the following sequence must be followed: 1. configure nvmcon to erase the required number of words: one, four or eight. 2. load tblpag and wreg with the eeprom address to be erased. 3. clear nvmif status bit and enable nvm interrupt (optional). 4. write the key sequence to nvmkey. 5. set the wr bit to begin erase cycle. 6. either poll the wr bit or wait for the nvm interrupt (nvmif set). a typical erase sequence is provided in example 6-2 . this example shows how to do a one-word erase. sim- ilarly, a four-word erase and an eight-word erase can be done. this example uses ?c? library procedures to manage the table pointer ( builtin_tblpage and builtin_tbloffset ) and the erase page pointer ( builtin_tblwtl ). the memory unlock sequence ( builtin_write_nvm ) also sets the wr bit to initiate the operation and returns control when complete. example 6-2: single-word erase int __attribute__ ((space(eedata))) eedata = 0x1234; // variable located in eeprom unsigned int offset; // set up nvmcon to erase one word of data eeprom nvmcon = 0x4058; // set up a pointer to the eeprom location to be erased tblpag = __builtin_tblpage(&eedata); // initialize ee data page pointer offset = __builtin_tbloffset(&eedata); // initizlize lower word of address __builtin_tblwtl(offset, 0); // write eeprom data to write latch asm volatile ("disi #5"); // disable interrupts for 5 instructions __builtin_write_nvm(); // issue unlock sequence & start write cycle
? 2008-2011 microchip technology inc. ds39927c-page 55 pic24f16ka102 family 6.4.1.1 data eeprom bulk erase to erase the entire data eeprom (bulk erase), the address registers do not need to be configured because this operation affects the entire data eeprom. the following sequence helps in performing bulk erase: 1. configure nvmcon to bulk erase mode. 2. clear nvmif status bit and enable nvm interrupt (optional). 3. write the key sequence to nvmkey. 4. set the wr bit to begin erase cycle. 5. either poll the wr bit or wait for the nvm interrupt (nvmif is set). a typical bulk erase sequence is provided in example 6-3 . 6.4.2 single-word write to write a single word in the data eeprom, the following sequence must be followed: 1. erase one data eeprom word (as mentioned in section 6.4.1 ?erase data eeprom? ) if the pgmonly bit (nvmcon<12>) is set to ? 1 ?. 2. write the data word into the data eeprom latch. 3. program the data word into the eeprom: - configure the nvmcon register to program one eeprom word (nvmcon<5:0> = 0001xx ). - clear nvmif status bit and enable nvm interrupt (optional). - write the key sequence to nvmkey. - set the wr bit to begin erase cycle. - either poll the wr bit or wait for the nvm interrupt (nvmif is set). - to get cleared, wait until nvmif is set. a typical single-word write sequence is provided in example 6-4 . example 6-3: data eeprom bulk erase example 6-4: single-word write to data eeprom // set up nvmcon to bulk erase the data eeprom nvmcon = 0x4050; // disable interrupts for 5 instructions asm volatile ("disi #5"); // issue unlock sequence and start erase cycle __builtin_write_nvm(); int __attribute__ ((space(eedata))) eedata = 0x1234; // variable located in eeprom,declared as a global variable. int newdata; // new data to write to eeprom unsigned int offset; // set up nvmcon to erase one word of data eeprom nvmcon = 0x4004; // set up a pointer to the eeprom location to be erased tblpag = __builtin_tblpage(&eedata); // initialize ee data page pointer offset = __builtin_tbloffset(&eedata); // initizlize lower word of address __builtin_tblwtl(offset, newdata); // write eeprom data to write latch asm volatile ("disi #5"); // disable interrupts for 5 instructions __builtin_write_nvm(); // issue unlock sequence & start write cycle
pic24f16ka102 family ds39927c-page 56 ? 2008-2011 microchip technology inc. 6.4.3 reading the data eeprom to read a word from data eeprom, the table read instruction is used. since the eeprom array is only 16 bits wide, only the tblrdl instruction is needed. the read operation is performed by loading tblpag and wreg with the address of the eeprom location, followed by a tblrdl instruction. a typical read sequence, using the table pointer manage- ment ( builtin_tblpage and builtin_tbloffset ) and table read ( builtin_tblrdl ) procedures from the c30 compiler library, is provided in example 6-5 . program space visibility (psv) can also be used to read locations in the data eeprom. example 6-5: reading the data eeprom using the tblrd command int __attribute__ ((space(eedata))) eedata = 0x1234; // variable located in eeprom,declared // as a global variable int data; // data read from eeprom unsigned int offset; // set up a pointer to the eeprom location to be erased tblpag = __builtin_tblpage(&eedata); // initialize ee data page pointer offset = __builtin_tbloffset(&eedata); // initizlize lower word of address data = __builtin_tblrdl(offset); // write eeprom data to write latch
? 2008-2011 microchip technology inc. ds39927c-page 57 pic24f16ka102 family 7.0 resets the reset module combines all reset sources and controls the device master reset signal, sysrst . the following is a list of device reset sources: ? por: power-on reset ?mclr : pin reset ?swr: reset instruction ? wdtr: watchdog timer reset ? bor: brown-out reset ? low-power bor/deep sleep bor ? trapr: trap conflict reset ? iopuwr: illegal opcode reset ? uwr: uninitialized w register reset figure 7-1 displays a simplified block diagram of the reset module. any active source of reset will make the sysrst signal active. many registers associated with the cpu and peripherals are forced to a known reset state. most registers are unaffected by a reset; their status is unknown on a power-on reset (por) and unchanged by all other resets. all types of device reset will set a corresponding status bit in the rcon register to indicate the type of reset (see register 7-1 ). a por will clear all bits except for the bor and por bits (rcon<1:0>) which are set. the user may set or clear any bit at any time during code execution. the rcon bits only serve as status bits. setting a particular reset status bit in software will not cause a device reset to occur. the rcon register also has other bits associated with the watchdog timer (wdt) and device power-saving states. the function of these bits is discussed in other sections of this manual. figure 7-1: reset sy stem block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on resets, refer to the ?pic24f family reference manual? , section 40. ?reset with programmable brown-out reset? (ds39728). note: refer to the specific peripheral or cpu section of this manual for register reset states. note: the status bits in the rcon register should be cleared after they are read so that the next rcon register value, after a device reset, will be meaningful. mclr v dd v dd rise detect por sleep or idle brown-out reset reset instruction wdt module glitch filter bor trap conflict illegal opcode uninitialized w register sysrst boren<1:0> 00 01 10 11 0 rcon sleep 1
pic24f16ka102 family ds39927c-page 58 ? 2008-2011 microchip technology inc. register 7-1: rcon: re set control register ( 1 ) r/w-0, hs r/w-0, hs r/w-0 u-0 u-0 r/c-0, hs r/w-0, hs r/w-0 trapr iopuwr sboren ? ? dpslp cm pmslp bit 15 bit 8 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-1, hs r/w-1, hs extr swr swdten ( 2 ) wdto sleep idle bor por bit 7 bit 0 legend: c = clearable bit hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 trapr: trap reset flag bit 1 = a trap conflict reset has occurred 0 = a trap conflict reset has not occurred bit 14 iopuwr: illegal opcode or uninitialized w access reset flag bit 1 = an illegal opcode detection, an illegal address mode or uninitialized w register used as an address pointer caused a reset 0 = an illegal opcode or uninitialized w reset has not occurred bit 13 sboren: software enable/disable of bor bit 1 = bor is turned on in software 0 = bor is turned off in software bit 12-11 unimplemented: read as ? 0 ? bit 10 dpslp: deep sleep mode flag bit 1 = deep sleep has occurred 0 = deep sleep has not occurred bit 9 cm: configuration word mismatch reset flag bit 1 = a configuration word mismatch has occurred 0 = a configuration word mismatch has not occurred bit 8 pmslp: program memory power during sleep bit 1 = program memory bias voltage remains powered during sleep 0 = program memory bias voltage is powered down during sleep bit 7 extr: external reset (mclr ) pin bit 1 = a master clear (pin) reset has occurred 0 = a master clear (pin) reset has not occurred bit 6 swr: software reset (instruction) flag bit 1 = a reset instruction has been executed 0 = a reset instruction has not been executed bit 5 swdten: software enable/disable of wdt bit ( 2 ) 1 = wdt is enabled 0 = wdt is disabled bit 4 wdto: watchdog timer time-out flag bit 1 = wdt time-out has occurred 0 = wdt time-out has not occurred note 1: all of the reset status bits may be set or cleared in software. setting one of these bits in software does not cause a device reset. 2: if the fwdten configuration bit is ? 1 ? (unprogrammed), the wdt is always enabled, regardless of the swdten bit setting.
? 2008-2011 microchip technology inc. ds39927c-page 59 pic24f16ka102 family table 7-1: reset flag bit operation bit 3 sleep: wake-up from sleep flag bit 1 = device has been in sleep mode 0 = device has not been in sleep mode bit 2 idle: wake-up from idle flag bit 1 = device has been in idle mode 0 = device has not been in idle mode bit 1 bor: brown-out reset flag bit 1 = a brown-out reset has occurred (the bor is also set after a por) 0 = a brown-out reset has not occurred bit 0 por: power-on reset flag bit 1 = a power-up reset has occurred 0 = a power-up reset has not occurred flag bit setting event clearing event trapr (rcon<15>) trap conflict event por iopuwr (rcon<14>) illegal opcode or uninitialized w register access por cm (rcon<9>) configuration mismatch reset por extr (rcon<7>) mclr reset por swr (rcon<6>) reset instruction por wdto (rcon<4>) wdt time-out pwrsav instruction, por sleep (rcon<3>) pwrsav #sleep instruction por idle (rcon<2>) pwrsav #idle instruction por bor (rcon<1>) por, bor ? por (rcon<0>) por ? dpslp (rcon<10>) pwrsav #sleep instruction with dscon set por note: all reset flag bits may be set or cleared by the user software. register 7-1: rcon: re set control register ( 1 ) (continued) note 1: all of the reset status bits may be set or cleared in software. setting one of these bits in software does not cause a device reset. 2: if the fwdten configuration bit is ? 1 ? (unprogrammed), the wdt is always enabled, regardless of the swdten bit setting.
pic24f16ka102 family ds39927c-page 60 ? 2008-2011 microchip technology inc. 7.1 clock source selection at reset if clock switching is enabled, the system clock source at device reset is chosen, as shown in table 7-2 . if clock switching is disabled, the system clock source is always selected according to the oscillator configuration bits. refer to section 9.0 ?oscillator configuration? for further details. table 7-2: oscillator selection vs. type of reset (clock switching enabled) 7.2 device reset times the reset times for various types of device reset are summarized in table 7-3 . note that the system reset signal, sysrst , is released after the por and pwrt delay times expire. the time at which the device actually begins to execute code will also depend on the system oscillator delays, which include the oscillator start-up timer (ost) and the pll lock time. the ost and pll lock times occur in parallel with the applicable sysrst delay times. the fscm delay determines the time at which the fscm begins to monitor the system clock source after the sysrst signal is released. table 7-3: reset delay times for various device resets reset type clock source determinant por fnosc configuration bits (fnosc<10:8>) bor mclr cosc control bits (osccon<14:12>) wdto swr reset type clock source sysrst delay system clock delay notes por ( 6 ) ec t por + t pwrt ? 1 , 2 frc, frcdiv t por + t pwrt t frc 1 , 2 , 3 lprc t por + t pwrt t lprc 1 , 2 , 3 ecpll t por + t pwrt t lock 1 , 2 , 4 frcpll t por + t pwrt t frc + t lock 1 , 2 , 3 , 4 xt, hs, sosc t por + t pwrt t ost 1 , 2 , 5 xtpll, hspll t por + t pwrt t ost + t lock 1 , 2 , 4 , 5 bor ec t pwrt ? 2 frc, frcdiv t pwrt t frc 2 , 3 lprc t pwrt t lprc 2 , 3 ecpll t pwrt t lock 2 , 4 frcpll t pwrt t frc + t lock 2 , 3 , 4 xt, hs, sosc t pwrt t ost 2 , 5 xtpll, hspll t pwrt t frc + t lock 2 , 3 , 4 all others any clock ? ? none note 1: t por = power-on reset (por) delay. 2: t pwrt = 64 ms nominal if the power-up timer (pwrt) is enabled; otherwise, it is zero. 3: t frc and t lprc = rc oscillator start-up times. 4: t lock = pll lock time. 5: t ost = oscillator start-up timer (ost). a 10-bit counter waits 1024 oscillator periods before releasing the oscillator clock to the system. 6: if two-speed start-up is enabled, regardless of the pr imary oscillator selected, the device starts with frc, and in such cases, frc start-up time is valid. note: for detailed operating frequency and timing specifications, see section 29.0 ?electrical characteristics? .
? 2008-2011 microchip technology inc. ds39927c-page 61 pic24f16ka102 family 7.2.1 por and long oscillator start-up times the oscillator start-up circuitry and its associated delay timers are not linked to the device reset delays that occur at power-up. some crystal circuits (especially low-frequency crystals) will have a relatively long start-up time. therefore, one or more of the following conditions is possible after sysrst is released: ? the oscillator circuit has not begun to oscillate. ? the oscillator start-up timer (ost) has not expired (if a crystal oscillator is used). ? the pll has not achieved a lock (if pll is used). the device will not begin to execute code until a valid clock source has been released to the system. there- fore, the oscillator and pll start-up delays must be considered when the reset delay time must be known. 7.2.2 fail-safe clock monitor (fscm) and device resets if the fscm is enabled, it will begin to monitor the system clock source when sysrst is released. if a valid clock source is not available at this time, the device will automatically switch to the frc oscillator and the user can switch to the desired crystal oscillator in the trap service routine (tsr). 7.3 special function register reset states most of the special function registers (sfrs) associ- ated with the pic24f cpu and peripherals are reset to a particular value at a device reset. the sfrs are grouped by their peripheral or cpu function and their reset values are specified in each section of this manual. the reset value for each sfr does not depend on the type of reset with the exception of four registers. the reset value for the reset control register, rcon, will depend on the type of device reset. the reset value for the oscillator control register, osccon, will depend on the type of reset and the programmed values of the fnosc bits in the flash configuration word (foscsel); see table 7-2 . the rcfgcal and nvmcon registers are only affected by a por. 7.4 deep sleep bor (dsbor) deep sleep bor is a very low-power bor circuitry, used when the device is in deep sleep mode. due to low-current consumption, accuracy may vary. the dsbor trip point is around 2.0v. dsbor is enabled by configuring dsboren (fds<6>) = 1 . dsboren will re-arm the por to ensure the device will reset if v dd drops below the por threshold. 7.5 brown-out reset (bor) the pic24f16ka102 family devices implement a bor circuit, which provides the user several configuration and power-saving options. the bor is controlled by the borv<1:0> and boren<1:0> configuration bits (fpor<6:5,1:0>). there are a total of four bor configurations, which are provided in tab l e 7 - 3 . the bor threshold is set by the borv<1:0> bits. if bor is enabled (any values of boren<1:0>, except ? 00 ?), any drop of v dd below the set threshold point will reset the device. the chip will remain in bor until v dd rises above threshold. if the power-up timer is enabled, it will be invoked after v dd rises above the threshold. then, it will keep the chip in reset for an additional time delay, t pwrt , if v dd drops below the threshold while the power-up timer is running. the chip goes back into a bor and the power-up timer will be initialized. once v dd rises above the threshold, the power-up timer will execute the additional time delay. bor and the power-up timer are independently configured. enabling the bor reset does not automatically enable the pwrt. 7.5.1 software enabled bor when boren<1:0> = 01 , the bor can be enabled or disabled by the user in software. this is done with the control bit, sboren (rcon<13>). setting sboren enables the bor to function as previously described. clearing the sboren disables the bor entirely. the sboren bit operates only in this mode; otherwise, it is read as ? 0 ?. placing bor under software control gives the user the additional flexibility of tailoring the application to its environment without having to reprogram the device to change the bor configuration. it also allows the user to tailor the incremental current that the bor con- sumes. while the bor current is typically very small, it may have some impact in low-power applications. note: even when the bor is under software control, the bor reset voltage level is still set by the borv<1:0> configuration bits; it can not be changed in software.
pic24f16ka102 family ds39927c-page 62 ? 2008-2011 microchip technology inc. 7.5.2 detecting bor when bor is enabled, the bor bit (rcon<1>) is always reset to ? 1 ? on any bor or por event. this makes it difficult to determine if a bor event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor. this assumes that the por and bor bits are reset to ? 0 ? in the software immediately after any por event. if the bor bit is ? 1 ? while the por bit is ? 0 ?, it can be reliably assumed that a bor event has occurred. 7.5.3 disabling bor in sleep mode when boren<1:0> = 10 , bor remains under hard- ware control and operates as previously described. however, whenever the device enters sleep mode, bor is automatically disabled. when the device returns to any other operating mode, bor is automatically re-enabled. this mode allows for applications to recover from brown-out situations, while actively executing code, when the device requires bor protection the most. at the same time, it saves additional power in sleep mode by eliminating the small incremental bor current. note: even when the device exits from deep sleep mode, both the por and bor are set.
? 2008-2011 microchip technology inc. ds39927c-page 63 pic24f16ka102 family 8.0 interrupt controller the pic24f interrupt controller reduces the numerous peripheral interrupt request signals to a single interrupt request signal to the cpu. it has the following features: ? up to eight processor exceptions and software traps ? seven user-selectable priority levels ? interrupt vector table (ivt) with up to 118 vectors ? unique vector for each interrupt or exception source ? fixed priority within a specified user priority level ? alternate interrupt vector table (aivt) for debug support ? fixed interrupt entry and return latencies 8.1 interrupt vector (ivt) table the ivt is displayed in figure 8-1 . the ivt resides in the program memory, starting at location, 000004h. the ivt contains 126 vectors, consisting of eight non-maskable trap vectors, plus, up to 118 sources of interrupt. in general, each interrupt source has its own vector. each interrupt vector contains a 24-bit wide address. the value programmed into each interrupt vector location is the starting address of the associated interrupt service routine (isr). interrupt vectors are prioritized in terms of their natural priority; this is linked to their position in the vector table. all other things being equal, lower addresses have a higher natural priority. for example, the interrupt associated with vector 0 will take priority over interrupts at any other vector address. pic24f16ka102 family devices implement non-maskable traps and unique interrupts; these are summarized in ta b l e 8 - 1 and tab l e 8 - 2 . 8.1.1 alternate interrupt vector ta b l e (a i v t ) the alternate interrupt vector table (aivt) is located after the ivt, as displayed in figure 8-1 . access to the aivt is provided by the altivt control bit (intcon2<15>). if the altivt bit is set, all interrupt and exception processes will use the alternate vectors instead of the default vectors. the alternate vectors are organized in the same manner as the default vectors. the aivt supports emulation and debugging efforts by providing a means to switch between an application and a support environment without requiring the interrupt vectors to be reprogrammed. this feature also enables switching between applications for evaluation of different software algorithms at run-time. if the aivt is not needed, the aivt should be programmed with the same addresses used in the ivt. 8.2 reset sequence a device reset is not a true exception because the interrupt controller is not involved in the reset process. the pic24f devices clear their registers in response to a reset, which forces the program counter (pc) to zero. the microcontroller then begins program execu- tion at location, 000000h. the user programs a goto instruction at the reset address, which redirects the program execution to the appropriate start-up routine. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the interrupt controller, refer to the ?pic24f family reference manual? , section 8. ?interrupts? (ds39707). note: any unimplemented or unused vector locations in the ivt and aivt should be programmed with the address of a default interrupt handler routine that contains a reset instruction.
pic24f16ka102 family ds39927c-page 64 ? 2008-2011 microchip technology inc. figure 8-1: pic24f interrupt vector table reset ? goto instruction 000000h reset ? goto address 000002h reserved 000004h oscillator fail trap vector address error trap vector stack error trap vector math error trap vector reserved reserved reserved interrupt vector 0 000014h interrupt vector 1 ? ? ? interrupt vector 52 00007ch interrupt vector 53 00007eh interrupt vector 54 000080h ? ? ? interrupt vector 116 0000fch interrupt vector 117 0000feh reserved 000100h reserved 000102h reserved oscillator fail trap vector address error trap vector stack error trap vector math error trap vector reserved reserved reserved interrupt vector 0 000114h interrupt vector 1 ? ? ? interrupt vector 52 00017ch interrupt vector 53 00017eh interrupt vector 54 000180h ? ? ? interrupt vector 116 interrupt vector 117 0001feh start of code 000200h decreasing natural order priority interrupt vector table (ivt) (1) alternate interrupt vector table (aivt) (1) note 1: see table 8-2 for the interrupt vector list.
? 2008-2011 microchip technology inc. ds39927c-page 65 pic24f16ka102 family table 8-2: implemented interrupt vectors table 8-1: trap vector details vector number ivt address aivt address trap source 0 000004h 000104h reserved 1 000006h 000106h oscillator failure 2 000008h 000108h address error 3 00000ah 00010ah stack error 4 00000ch 00010ch math error 5 00000eh 00010eh reserved 6 000010h 000110h reserved 7 000012h 000112h reserved interrupt source vector number ivt address aivt address interrupt bit locations flag enable priority adc1 conversion done 13 00002eh 00012eh ifs0<13> iec0<13> ipc3<6:4> comparator event 18 000038h 000138h ifs1<2> iec1<2> ipc4<10:8> crc generator 67 00009ah 00019ah ifs4<3> iec4<3> ipc16<14:12> ctmu 77 0000aeh 0001aeh ifs4<13> iec4<13> ipc19<6:4> external interrupt 0 0 000014h 000114h ifs0<0> iec0<0> ipc0<2:0> external interrupt 1 20 00003ch 00013ch ifs1<4> iec1<4> ipc5<2:0> external interrupt 2 29 00004eh 00014eh ifs1<13> iec1<13> ipc7<6:4> i2c1 master event 17 000036h 000136h ifs1<1> iec1<1> ipc4<6:4> i2c1 slave event 16 000034h 000134h ifs1<0> iec1<0> ipc4<2:0> input capture 1 1 000016h 000116h ifs0<1> iec0<1> ipc0<6:4> input change notification 19 00003ah 00013ah ifs1<3> iec1<3> ipc4<14:12> hlvd high/low-voltage detect 72 0000a4h 0001a4h ifs4<8> iec4<8> ipc17<2:0> nvm ? nvm write complete 15 000032h 000132h ifs0<15> iec0<15> ipc3<14:12> output compare 1 2 000018h 000118h ifs0<2> iec0<2> ipc0<10:8> real-time clock/calendar 62 000090h 000190h ifs3<14> iec3<14> ipc15<10:8> spi1 error 9 000026h 000126h ifs0<9> iec0<9> ipc2<6:4> spi1 event 10 000028h 000128h ifs0<10> iec0<10> ipc2<10:8> timer1 3 00001ah 00011ah ifs0<3> iec0<3> ipc0<14:12> timer2 7 000022h 000122h ifs0<7> iec0<7> ipc1<14:12> timer3 8 000024h 000124h ifs0<8> iec0<8> ipc2<2:0> uart1 error 65 000096h 000196h ifs4<1> iec4<1> ipc16<6:4> uart1 receiver 11 00002ah 00012ah ifs0<11> iec0<11> ipc2<14:12> uart1 transmitter 12 00002ch 00012ch ifs0<12> iec0<12> ipc3<2:0> uart2 error 66 000098h 000198h ifs4<2> iec4<2> ipc16<10:8> uart2 receiver 30 000050h 000150h ifs1<14> iec1<14> ipc7<10:8> uart2 transmitter 31 000052h 000152h ifs1<15> iec1<15> ipc7<14:12>
pic24f16ka102 family ds39927c-page 66 ? 2008-2011 microchip technology inc. 8.3 interrupt control and status registers the pic24f16ka102 family of devices implements a total of 22 registers for the interrupt controller: ? intcon1 ? intcon2 ? ifs0, ifs1, ifs3 and ifs4 ? iec0, iec1, iec3 and iec4 ? ipc0 through ipc5, ipc7 and ipc15 through ipc19 ?inttreg global interrupt control functions are controlled from intcon1 and intcon2. intcon1 contains the interrupt nesting disable (nstdis) bit, as well as the control and status flags for the processor trap sources. the intcon2 register controls the external interrupt request signal behavior and the use of the aiv table. the ifsx registers maintain all of the interrupt request flags. each source of interrupt has a status bit, which is set by the respective peripherals, or external signal, and is cleared via software. the iecx registers maintain all of the interrupt enable bits. these control bits are used to individually enable interrupts from the peripherals or external signals. the ipcx registers are used to set the interrupt priority level for each source of interrupt. each user interrupt source can be assigned to one of eight priority levels. the inttreg register contains the associated inter- rupt vector number and the new cpu interrupt priority level, which are latched into the vector number (vecnum<6:0>) and the interrupt level (ilr<3:0>) bit fields in the inttreg register. the new interrupt priority level is the priority of the pending interrupt. the interrupt sources are assigned to the ifsx, iecx and ipcx registers in the same sequence listed in table 8-2 . for example, the int0 (external interrupt 0) is depicted as having a vector number and a natural order priority of 0. thus, the int0if status bit is found in ifs0<0>, the int0ie enable bit in iec0<0> and the int0ip<2:0> priority bits in the first position of ipc0 (ipc0<2:0>). although they are not specifically part of the interrupt control hardware, two of the cpu control registers contain bits that control interrupt functionality. the alu status register (sr) contains the ipl<2:0> bits (sr<7:5>). these indicate the current cpu interrupt priority level. the user may change the current cpu priority level by writing to the ipl bits. the corcon register contains the ipl3 bit, which together with ipl<2:0>, also indicates the current cpu priority level. ipl3 is a read-only bit so that the trap events cannot be masked by the user?s software. all interrupt registers are described in register 8-1 through register 8-21 , in the following sections.
? 2008-2011 microchip technology inc. ds39927c-page 67 pic24f16ka102 family register 8-1: sr: alu status register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc ? ? ? ? ? ? ? dc ( 1 ) bit 15 bit 8 r/w-0, hsc r/w-0, hsc r/w-0, hsc r-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc ipl2 ( 2 , 3 ) ipl1 ( 2 , 3 ) ipl0 ( 2 , 3 ) ra ( 1 ) n ( 1 ) ov ( 1 ) z ( 1 ) c ( 1 ) bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 7-5 ipl<2:0>: cpu interrupt priority level status bits ( 2 , 3 ) 111 = cpu interrupt priority level is 7 (15); user interrupts disabled 110 = cpu interrupt priority level is 6 (14) 101 = cpu interrupt priority level is 5 (13) 100 = cpu interrupt priority level is 4 (12) 011 = cpu interrupt priority level is 3 (11) 010 = cpu interrupt priority level is 2 (10) 001 = cpu interrupt priority level is 1 (9) 000 = cpu interrupt priority level is 0 (8) note 1: see register 3-1 for the description of these bits, which are not dedicated to interrupt control functions. 2: the ipl bits are concatenated with the ipl3 bit (corcon<3>) to form the cpu interrupt priority level. the value in parentheses indicates the interrupt priority level if ipl3 = 1 . 3: the ipl status bits are read-only when nstdis (intcon1<15>) = 1 . note: bit 8 and bits 4 through 0 are described in section 3.0 ?cpu? .
pic24f16ka102 family ds39927c-page 68 ? 2008-2011 microchip technology inc. register 8-2: corcon: cpu control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/c-0, hsc r/w-0 u-0 u-0 ? ? ? ?ipl3 ( 2 ) psv ( 1 ) ? ? bit 7 bit 0 legend: c = clearable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3 ipl3: cpu interrupt priority level status bit ( 2 ) 1 = cpu interrupt priority level is greater than 7 0 = cpu interrupt priority level is 7 or less bit 1-0 unimplemented: read as ? 0 ? note 1: see register 3-2 for the description of this bit, which is not dedicated to interrupt control functions. 2: the ipl3 bit is concatenated with the ipl<2:0> bits (sr<7:5>) to form the cpu interrupt priority level. note: bit 2 is described in section 3.0 ?cpu? .
? 2008-2011 microchip technology inc. ds39927c-page 69 pic24f16ka102 family register 8-3: intcon1: in terrupt control register 1 r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 nstdis ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs u-0 ? ? ? matherr addrerr stkerr oscfail ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nstdis: interrupt nesting disable bit 1 = interrupt nesting is disabled 0 = interrupt nesting is enabled bit 14-5 unimplemented: read as ? 0 ? bit 4 matherr: arithmetic error trap status bit 1 = overflow trap has occurred 0 = overflow trap has not occurred bit 3 addrerr: address error trap status bit 1 = address error trap has occurred 0 = address error trap has not occurred bit 2 stkerr: stack error trap status bit 1 = stack error trap has occurred 0 = stack error trap has not occurred bit 1 oscfail: oscillator failure trap status bit 1 = oscillator failure trap has occurred 0 = oscillator failure trap has not occurred bit 0 unimplemented: read as ? 0 ?
pic24f16ka102 family ds39927c-page 70 ? 2008-2011 microchip technology inc. register 8-4: intcon2: in terrupt control register2 r/w-0 r-0, hsc u-0 u-0 u-0 u-0 u-0 u-0 altivt disi ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 ? ? ? ? ? int2ep int1ep int0ep bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 altivt: enable alternate interrupt vector table bit 1 = use alternate interrupt vector table 0 = use standard (default) vector table bit 14 disi: disi instruction status bit 1 = disi instruction is active 0 = disi instruction is not active bit 13-3 unimplemented: read as ? 0 ? bit 2 int2ep: external interrupt 2 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge bit 1 int1ep: external interrupt 1 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge bit 0 int0ep: external interrupt 0 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge
? 2008-2011 microchip technology inc. ds39927c-page 71 pic24f16ka102 family register 8-5: ifs0: interrupt flag status register 0 r/w-0, hs u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs nvmif ? ad1if u1txif u1rxif spi1if spf1if t3if bit 15 bit 8 r/w-0, hs u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs t2if ? ? ? t1if oc1if ic1if int0if bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nvmif: nvm interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 14 unimplemented: read as ? 0 ? bit 13 ad1if: a/d conversion complete interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12 u1txif: uart1 transmitter interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 11 u1rxif: uart1 receiver interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 10 spi1if: spi1 event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 9 spf1if: spi1 fault interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 8 t3if: timer3 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 7 t2if: timer2 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 6-4 unimplemented: read as ? 0 ? bit 3 t1if: timer1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 oc1if: output compare channel 1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 ic1if: input capture channel 1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 int0if: external interrupt 0 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
pic24f16ka102 family ds39927c-page 72 ? 2008-2011 microchip technology inc. register 8-6: ifs1: interrupt flag status register 1 r/w-0, hs r/w-0, hs r/w-0, hs u-0 u-0 u-0 u-0 u-0 u2txif u2rxif int2if ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0 r/w-0 ? ? ? int1if cnif cmif mi2c1if si2c1if bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 u2txif: uart2 transmitter interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 14 u2rxif: uart2 receiver interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 13 int2if: external interrupt 2 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12-5 unimplemented: read as ? 0 ? bit 4 int1if: external interrupt 1 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 3 cnif: input change notification interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 cmif: comparator interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 mi2c1if: master i2c1 event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 si2c1if: slave i2c1 event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
? 2008-2011 microchip technology inc. ds39927c-page 73 pic24f16ka102 family register 8-7: ifs3: interrupt flag status register 3 u-0 r/w-0, hs u-0 u-0 u-0 u-0 u-0 u-0 ?rtcif ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14 rtcif: real-time clock and calendar interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 13-0 unimplemented: read as ? 0 ?
pic24f16ka102 family ds39927c-page 74 ? 2008-2011 microchip technology inc. register 8-8: ifs4: interrupt flag status register 4 u-0 u-0 r/w-0, hs u-0 u-0 u-0 u-0 r/w-0, hs ? ?ctmuif ? ? ? ?hlvdif bit 15 bit 8 u-0 u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs u-0 ? ? ? ? crcif u2erif u1erif ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 ctmuif: ctmu interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12-9 unimplemented: read as ? 0 ? bit 8 hlvdif: high/low-voltage detect interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 7-4 unimplemented: read as ? 0 ? bit 3 crcif: crc generator interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 u2erif: uart2 error interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 u1erif: uart1 error interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 75 pic24f16ka102 family register 8-9: iec0: interrupt enable control register 0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 nvmie ? ad1ie u1txie u1rxie spi1ie spf1ie t3ie bit 15 bit 8 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 t2ie ? ? ? t1ie oc1ie ic1ie int0ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nvmie: nvm interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 14 unimplemented: read as ? 0 ? bit 13 ad1ie: a/d conversion complete interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 12 u1txie: uart1 transmitter interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 11 u1rxie: uart1 receiver interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 10 spi1ie: spi1 transfer complete interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 9 spf1ie: spi1 fault interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 8 t3ie: timer3 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 7 t2ie: timer2 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request not is enabled bit 6-4 unimplemented: read as ? 0 ? bit 3 t1ie: timer1 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 2 oc1ie: output compare channel 1 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 ic1ie: input capture channel 1 interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 int0ie: external interrupt 0 enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled
pic24f16ka102 family ds39927c-page 76 ? 2008-2011 microchip technology inc. register 8-10: iec1: interrupt enable control register 1 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 u-0 u2txie u2rxie int2ie ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? int1ie cnie cmie mi2c1ie si2c1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 u2txie: uart2 transmitter interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 14 u2rxie: uart2 receiver interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 13 int2ie: external interrupt 2 enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 12-5 unimplemented: read as ? 0 ? bit 4 int1ie: external interrupt 1 enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 3 cnie: input change notification interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 2 cmie: comparator interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 mi2c1ie: master i2c1 event interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 si2c1ie: slave i2c1 event interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled
? 2008-2011 microchip technology inc. ds39927c-page 77 pic24f16ka102 family register 8-11: iec3: interrupt enable control register 3 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 ?rtcie ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14 rtcie: real-time clock and calendar interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 13-0 unimplemented: read as ? 0 ?
pic24f16ka102 family ds39927c-page 78 ? 2008-2011 microchip technology inc. register 8-12: iec4: interrupt enable control register 4 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 r/w-0 ? ?ctmuie ? ? ? ?hlvdie bit 15 bit 8 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 ? ? ? ? crcie u2erie u1erie ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 ctmuie: ctmu interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 12-9 unimplemented: read as ? 0 ? bit 8 hlvdie: high/low-voltage detect interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 7-4 unimplemented: read as ? 0 ? bit 3 crcie: crc generator interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 2 u2erie: uart2 error interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 1 u1erie: uart1 error interrupt enable bit 1 = interrupt request is enabled 0 = interrupt request is not enabled bit 0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 79 pic24f16ka102 family register 8-13: ipc0: interrupt pr iority control register 0 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? t1ip2 t1ip1 t1ip0 ? oc1ip2 oc1ip1 oc1ip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? ic1ip2 ic1ip1 ic1ip0 ? int0ip2 int0ip1 int0ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t1ip<2:0>: timer1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 oc1ip<2:0>: output compare channel 1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 ic1ip<2:0>: input capture channel 1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 int0ip<2:0>: external interrupt 0 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f16ka102 family ds39927c-page 80 ? 2008-2011 microchip technology inc. register 8-14: ipc1: interrupt pr iority control register 1 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? t2ip2 t2ip1 t2ip0 ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t2ip<2:0>: timer2 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 81 pic24f16ka102 family register 8-15: ipc2: interrupt pr iority control register 2 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? u1rxip2 u1rxip1 u1rxip0 ? spi1ip2 spi1ip1 spi1ip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? spf1ip2 spf1ip1 spf1ip0 ? t3ip2 t3ip1 t3ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 u1rxip<2:0>: uart1 receiver interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 spi1ip<2:0>: spi1 event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 spf1ip<2:0>: spi1 fault interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 t3ip<2:0>: timer3 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f16ka102 family ds39927c-page 82 ? 2008-2011 microchip technology inc. register 8-16: ipc3: interrupt pr iority control register 3 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? nvmip2 nvmip1 nvmip0 ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? ad1ip2 ad1ip1 ad1ip0 ? u1txip2 u1txip1 u1txip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 nvmip<2:0>: nvm interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-7 unimplemented: read as ? 0 ? bit 6-4 ad1ip<2:0>: a/d conversion complete interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 u1txip<2:0>: uart1 transmitter interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2008-2011 microchip technology inc. ds39927c-page 83 pic24f16ka102 family register 8-17: ipc4: interrupt pr iority control register 4 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? cnip2 cnip1 cnip0 ?cmip2cmip1cmip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? mi2c1p2 mi2c1p1 mi2c1p0 ? si2c1p2 si2c1p1 si2c1p0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 cnip<2:0>: input change notification interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 cmip<2:0>: comparator interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 mi2c1p<2:0>: master i2c1 event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 si2c1p<2:0>: slave i2c1 event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f16ka102 family ds39927c-page 84 ? 2008-2011 microchip technology inc. register 8-18: ipc5: interrupt pr iority control register 5 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? int1ip2 int1ip1 int1ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2-0 int1ip<2:0>: external interrupt 1 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2008-2011 microchip technology inc. ds39927c-page 85 pic24f16ka102 family register 8-19: ipc7: interrupt pr iority control register 7 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? u2txip2 u2txip1 u2txip0 ? u2rxip2 u2rxip1 u2rxip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? int2ip2 int2ip1 int2ip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 u2txip<2:0>: uart2 transmitter interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 u2rxip<2:0>: uart2 receiver interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 int2ip<2:0>: external interrupt 2 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
pic24f16ka102 family ds39927c-page 86 ? 2008-2011 microchip technology inc. register 8-20: ipc15: interrupt priority control register 15 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? rtcip2 rtcip1 rtcip0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-11 unimplemented: read as ? 0 ? bit 10-8 rtcip<2:0>: real-time clock and calendar interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7-0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 87 pic24f16ka102 family register 8-21: ipc16: interrupt priority control register 16 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? crcip2 crcip1 crcip0 ? u2erip2 u2erip1 u2erip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? u1erip2 u1erip1 u1erip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 crcip<2:0>: crc generator error interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 u2erip<2:0>: uart2 error interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 u1erip<2:0>: uart1 error interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
pic24f16ka102 family ds39927c-page 88 ? 2008-2011 microchip technology inc. register 8-22: ipc18: interrupt priority control register 18 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? hlvdip2 hlvdip1 hlvdip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2-0 hlvdip<2:0>: high/low-voltage detect interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled register 8-23: ipc19: interrupt priority control register 19 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? ctmuip2 ctmuip1 ctmuip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-4 ctmuip<2:0>: ctmu interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 89 pic24f16ka102 family register 8-24: inttreg: interrupt control and status register r-0 u-0 r/w-0 u-0 r-0 r-0 r-0 r-0 cpuirq ?vhold ? ilr3 ilr2 ilr1 ilr0 bit 15 bit 8 u-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 ? vecnum6 vecnum5 vecnum4 vecnum3 vecnum2 vecnum1 vecnum0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 cpuirq: interrupt request from interrupt controller cpu bit 1 = an interrupt request has occurred but has not yet been acknowledged by the cpu (this will happen when the cpu priority is higher than the interrupt priority) 0 = no interrupt request is left unacknowledged bit 14 unimplemented: read as ? 0 ? bit 13 vhold: allows vector number capture and changes what interrupt is stored in vecnum bit 1 = vecnum will contain the value of the highest priority pending interrupt, instead of the current interrupt 0 = vecnum will contain the value of the last acknowledged interrupt (last interrupt that has occurred with higher priority than the cpu, even if other interrupts are pending) bit 12 unimplemented: read as ? 0 ? bit 11-8 ilr<3:0>: new cpu interrupt priority level bits 1111 = cpu interrupt priority level is 15 ? ? ? 0001 = cpu interrupt priority level is 1 0000 = cpu interrupt priority level is 0 bit 7 unimplemented: read as ? 0 ? bit 6-0 vecnum<6:0>: vector number of pending interrupt bits 0111111 = interrupt vector pending is number 135 ? ? ? 0000001 = interrupt vector pending is number 9 0000000 = interrupt vector pending is number 8
pic24f16ka102 family ds39927c-page 90 ? 2008-2011 microchip technology inc. 8.4 interrupt setup procedures 8.4.1 initialization to configure an interrupt source: 1. set the nstdis control bit (intcon1<15>) if nested interrupts are not desired. 2. select the user-assigned priority level for the interrupt source by writing the control bits in the appropriate ipcx register. the priority level will depend on the specific application and type of interrupt source. if multiple priority levels are not desired, the ipcx register control bits, for all enabled interrupt sources, may be programmed to the same non-zero value. 3. clear the interrupt flag status bit associated with the peripheral in the associated ifsx register. 4. enable the interrupt source by setting the interrupt enable control bit associated with the source in the appropriate iecx register. 8.4.2 interrupt service routine the method that is used to declare an isr and initialize the ivt with the correct vector address depends on the programming language (i.e., c or assembler) and the language development toolsuite that is used to develop the application. in general, the user must clear the interrupt flag in the appropriate ifsx register for the source of the interrupt that the isr handles. otherwise, the isr will be re-entered immediately after exiting the routine. if the isr is coded in assembly language, it must be terminated using a retfie instruction to unstack the saved pc value, srl value and old cpu priority level. 8.4.3 trap service routine (tsr) a trap service routine (tsr) is coded like an isr, except that the appropriate trap status flag in the intcon1 register must be cleared to avoid re-entry into the tsr. 8.4.4 interrupt disable all user interrupts can be disabled using the following procedure: 1. push the current sr value onto the software stack using the push instruction. 2. force the cpu to priority level 7 by inclusive oring the value oeh with srl. to enable user interrupts, the pop instruction may be used to restore the previous sr value. only user interrupts with a priority level of 7 or less can be disabled. trap sources (levels 8-15) cannot be disabled. the disi instruction provides a convenient way to disable interrupts of priority levels 1-6 for a fixed period. level 7 interrupt sources are not disabled by the disi instruction. note: at a device reset, the ipcx registers are initialized, such that all user interrupt sources are assigned to priority level 4.
? 2008-2011 microchip technology inc. ds39927c-page 91 pic24f16ka102 family 9.0 oscillator configuration the oscillator system for the pic24f16ka102 family of devices has the following features: ? a total of five external and internal oscillator options as clock sources, providing 11 different clock modes. ? on-chip 4x phase locked loop (pll) to boost internal operating frequency on select internal and external oscillator sources. ? software-controllable switching between various clock sources. ? software-controllable postscaler for selective clocking of cpu for system power savings. ? system frequency range declaration bits for ec mode. when using an external clock source, the current consumption is reduced by setting the declaration bits to the expected frequency range. ? a fail-safe clock monitor (fscm) that detects clock failure and permits safe application recovery or shutdown. figure 9-1 provides a simplified diagram of the oscillator system. figure 9-1: pic24f16ka102 family clock diagram note: this data sheet summarizes the fea- tures of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on oscillator configuration, refer to the ?pic24f family reference manual? , section 38. ?oscillator with 500 khz low-power frc? (ds39726). secondary oscillator soscen enable oscillator sosco sosci clock source option for other modules osci osco primary oscillator xt, hs, ec postscaler clkdiv<10:8> wdt, pwrt, dswdt frcdiv 31 khz (nominal) 8 mhz frc lprc oscillator sosc lprc clock control logic fail-safe clock monitor frc 4 x pll xtpll, hspll ecpll,frcpll 8 mhz 4 mhz cpu peripherals postscaler clkdiv<14:12> clko reference clock generator refo refocon<15:8> oscillator 500 khz lpfrc oscillator
pic24f16ka102 family ds39927c-page 92 ? 2008-2011 microchip technology inc. 9.1 cpu clocking scheme the system clock source can be provided by one of four sources: ? primary oscillator (posc) on the osci and osco pins ? secondary oscillator (sosc) on the sosci and sosco pins the pic24f16ka102 family devices consist of two types of secondary oscillator: - high-power secondary oscillator - low-power secondary oscillator these can be selected by using the soscsel (fosc<5>) bit. ? fast internal rc (frc) oscillator - 8 mhz frc oscillator - 500 khz lower power frc oscillator ? low-power internal rc (lprc) oscillator the primary oscillator and 8 mhz frc sources have the option of using the internal 4x pll. the frequency of the frc clock source can optionally be reduced by the programmable clock divider. the selected clock source generates the processor and peripheral clock sources. the processor clock source is divided by two to produce the internal instruction cycle clock, f cy . in this docu- ment, the instruction cycle clock is also denoted by f osc /2. the internal instruction cycle clock, f osc /2, can be provided on the osco i/o pin for some operating modes of the primary oscillator. 9.2 initial configuration on por the oscillator source (and operating mode) that is used at a device power-on reset (por) event is selected using configuration bit settings. the oscillator configuration bit settings are located in the configuration registers in the program memory (refer to section 26.1 ?configuration bits? for further details). the primary oscillator configuration bits, poscmd<1:0> (fosc<1:0>), and the initial oscillator select configura- tion bits, fnosc<2:0> (foscsel<2:0>), select the oscillator source that is used at a por. the frc primary oscillator with postscaler (frcdiv) is the default (unpro- grammed) selection. the secondary oscillator, or one of the internal oscillators, may be chosen by programming these bit locations. the ec mode frequency range configuration bits, poscfreq<1:0> (fosc<4:3>), optimize power consumption when running in ec mode. the default configuration is ?frequency range is greater than 8 mhz?. the configuration bits allow users to choose between the various clock modes, shown in tab l e 9 - 1 . 9.2.1 clock switching mode configuration bits the fcksm configuration bits (fosc<7:6>) are used jointly to configure device clock switching and the fscm. clock switching is enabled only when fcksm1 is programmed (? 0 ?). the fscm is enabled only when fcksm<1:0> are both programmed (? 00 ?). table 9-1: configuration bit va lues for clock selection oscillator mode oscillator source poscmd<1:0> fnosc<2:0> note 8 mhz frc oscillator with postscaler (frcdiv) internal 11 111 1 , 2 500 mhz frc oscillator with postscaler (lpfrcdiv) internal 11 110 1 low-power rc oscillator (lprc) internal 11 101 1 secondary (timer1) oscillator (sosc) secondary 00 100 1 primary oscillator (hs) with pll module (hspll) primary 10 011 primary oscillator (ec) with pll module (ecpll) primary 00 011 primary oscillator (hs) primary 10 010 primary oscillator (xt) primary 01 010 primary oscillator (ec) primary 00 010 8 mhz frc oscillator with pll module (frcpll) internal 11 001 1 8 mhz frc oscillator (frc) internal 11 000 1 note 1: osco pin function is determined by the osciofnc configuration bit. 2: this is the default oscillator mode for an unprogrammed (erased) device.
? 2008-2011 microchip technology inc. ds39927c-page 93 pic24f16ka102 family 9.3 control registers the operation of the oscillator is controlled by three special function registers (sfrs): ? osccon ?clkdiv ?osctun the osccon register ( register 9-1 ) is the main con- trol register for the oscillator. it controls clock source switching and allows the monitoring of clock sources. the clock divider register ( register 9-2 ) controls the features associated with doze mode, as well as the postscaler for the frc oscillator. the frc oscillator tune register ( register 9-3 ) allows the user to fine tune the frc oscillator over a range of approximately 5.25%. each bit increment or decre- ment changes the factory calibrated frequency of the frc oscillator by a fixed amount. register 9-1: osccon: os cillator control register u-0 r-0, hsc r-0, hsc r-0, hsc u-0 r/w-x ( 1 ) r/w-x ( 1 ) r/w-x ( 1 ) ? cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 bit 15 bit 8 r/so-0, hsc u-0 r-0, hsc ( 2 ) u-0 r/co-0, hs u-0 r/w-0 r/w-0 clklock ?lock ?cf ? soscen oswen bit 7 bit 0 legend: co = clearable only bit so = settable only bit hs = hardware settable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 cosc<2:0>: current oscillator selection bits 111 = 8 mhz fast rc oscillator with postscaler (frcdiv) 110 = 500 khz low-power fast rc oscillator (frc) with postscaler (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (xtpll, hspll, ecpll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with postscaler and pll module (frcpll) 000 = 8 mhz frc oscillator (frc) bit 11 unimplemented: read as ? 0 ? bit 10-8 nosc<2:0>: new oscillator selection bits ( 1 ) 111 = 8 mhz fast rc oscillator with postscaler (frcdiv) 110 = 500 khz low-power fast rc oscillator (frc) with postscaler (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (xtpll, hspll, ecpll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with postscaler and pll module (frcpll) 000 = 8 mhz frc oscillator (frc) note 1: reset values for these bits are determined by the fnosc configuration bits. 2: also resets to ? 0 ? during any valid clock switch or whenever a non-pll clock mode is selected.
pic24f16ka102 family ds39927c-page 94 ? 2008-2011 microchip technology inc. bit 7 clklock: clock selection lock enabled bit if fscm is enabled (fcksm1 = 1 ): 1 = clock and pll selections are locked 0 = clock and pll selections are not locked and may be modified by setting the oswen bit if fscm is disabled (fcksm1 = 0 ): clock and pll selections are never locked and may be modified by setting the oswen bit. bit 6 unimplemented: read as ? 0 ? bit 5 lock: pll lock status bit ( 2 ) 1 = pll module is in lock or pll module start-up timer is satisfied 0 = pll module is out of lock, pll start-up timer is running or pll is disabled bit 4 unimplemented: read as ? 0 ? bit 3 cf: clock fail detect bit 1 = fscm has detected a clock failure 0 = no clock failure has been detected bit 2 unimplemented: read as ? 0 ? bit 1 soscen: 32 khz secondary oscillator (sosc) enable bit 1 = enable secondary oscillator 0 = disable secondary oscillator bit 0 oswen: oscillator switch enable bit 1 = initiate an oscillator switch to clock source specified by nosc<2:0> bits 0 = oscillator switch is complete register 9-1: osccon: oscillato r control register (continued) note 1: reset values for these bits are determined by the fnosc configuration bits. 2: also resets to ? 0 ? during any valid clock switch or whenever a non-pll clock mode is selected.
? 2008-2011 microchip technology inc. ds39927c-page 95 pic24f16ka102 family register 9-2: clkdiv: clock divider register r/w-0 r/w-0 r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 roi doze2 doze1 doze0 dozen ( 1 ) rcdiv2 rcdiv1 rcdiv0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 roi: recover on interrupt bit 1 = interrupts clear the dozen bit and reset the cpu and peripheral clock ratio to 1:1 0 = interrupts have no effect on the dozen bit bit 14-12 doze<2:0>: cpu and peripheral clock ratio select bits 111 = 1:128 110 = 1:64 101 = 1:32 100 = 1:16 011 = 1:8 010 = 1:4 001 = 1:2 000 = 1:1 bit 11 dozen: doze enable bit ( 1 ) 1 = doze<2:0> bits specify the cpu and peripheral clock ratio 0 = cpu and peripheral clock ratio are set to 1:1 bit 10-8 rcdiv<2:0>: frc postscaler select bits when osccon (cosc<2:0>) = 111 : 111 = 31.25 khz (divide by 256) 110 = 125 khz (divide by 64) 101 = 250 khz (divide by 32) 100 = 500 khz (divide by 16) 011 = 1 mhz (divide by 8) 010 = 2 mhz (divide by 4) 001 = 4 mhz (divide by 2) (default) 000 = 8 mhz (divide by 1) when osccon (cosc<2:0>) = 110 : 111 = 1.95 khz (divide by 256) 110 = 7.81 khz (divide by 64) 101 = 15.62 khz (divide by 32) 100 = 31.25 khz (divide by 16) 011 = 62.5 khz (divide by 8) 010 = 125 khz (divide by 4) 001 = 250 khz (divide by 2) (default) 000 = 500 khz (divide by 1) bit 7-0 unimplemented: read as ? 0 ? note 1: this bit is automatically cleared when the roi bit is set and an interrupt occurs.
pic24f16ka102 family ds39927c-page 96 ? 2008-2011 microchip technology inc. register 9-3: osctun: frc oscillator tune register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? tun5 ( 1 ) tun4 ( 1 ) tun3 ( 1 ) tun2 ( 1 ) tun1 ( 1 ) tun0 ( 1 ) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 unimplemented: read as ? 0 ? bit 5-0 tun<5:0>: frc oscillator tuning bits ( 1 ) 011111 = maximum frequency deviation 011110 000001 000000 = center frequency, oscillator is running at factory calibrated frequency 111111 100001 100000 = minimum frequency deviation note 1: increments or decrements of tun<5:0> may not change the frc frequency in equal steps over the frc tuning range and may not be monotonic.
? 2008-2011 microchip technology inc. ds39927c-page 97 pic24f16ka102 family 9.4 clock switching operation with few limitations, applications are free to switch between any of the four clock sources (posc, sosc, frc and lprc) under software control and at any time. to limit the possible side effects that could result from this flexibility, pic24f devices have a safeguard lock built into the switching process. 9.4.1 enabling clock switching to enable clock switching, the fcksm1 configuration bit in the fosc configuration register must be programmed to ? 0 ?. (refer to section 26.1 ?configuration bits? for further details.) if the fcksm1 configuration bit is unpro- grammed (? 1 ?), the clock switching function and fscm function are disabled; this is the default setting. the noscx control bits (osccon<10:8>) do not control the clock selection when clock switching is disabled. however, the coscx bits (osccon<14:12>) will reflect the clock source selected by the fnoscx configuration bits. the oswen control bit (osccon<0>) has no effect when clock switching is disabled; it is held at ? 0 ? at all times. 9.4.2 oscillator switching sequence at a minimum, performing a clock switch requires this basic sequence: 1. if desired, read the coscx bits (osccon<14:12>), to determine the current oscillator source. 2. perform the unlock sequence to allow a write to the osccon register high byte. 3. write the appropriate value to the noscx bits (osccon<10:8>) for the new oscillator source. 4. perform the unlock sequence to allow a write to the osccon register low byte. 5. set the oswen bit to initiate the oscillator switch. once the basic sequence is completed, the system clock hardware responds automatically as follows: 1. the clock switching hardware compares the coscx bits with the new value of the noscx bits. if they are the same, then the clock switch is a redundant operation. in this case, the oswen bit is cleared automatically and the clock switch is aborted. 2. if a valid clock switch has been initiated, the lock (osccon<5>) and cf (osccon<3>) bits are cleared. 3. the new oscillator is turned on by the hardware if it is not currently running. if a crystal oscillator must be turned on, the hardware will wait until the ost expires. if the new source is using the pll, then the hardware waits until a pll lock is detected (lock = 1 ). 4. the hardware waits for 10 clock cycles from the new clock source and then performs the clock switch. 5. the hardware clears the oswen bit to indicate a successful clock transition. in addition, the noscx bits value is transferred to the coscx bits. 6. the old clock source is turned off at this time, with the exception of lprc (if wdt, fscm or rtcc with lprc as clock source are enabled) or sosc (if soscen remains enabled). note: the primary oscillator mode has three different submodes (xt, hs and ec), which are determined by the poscmdx configuration bits. while an application can switch to and from primary oscillator mode in software, it cannot switch between the different primary submodes without reprogramming the device. note 1: the processor will continue to execute code throughout the clock switching sequence. timing-sensitive code should not be executed during this time. 2: direct clock switches between any primary oscillator mode with pll and frcpll mode are not permitted. this applies to clock switches in either direction. in these instances, the application must switch to frc mode as a transition clock source between the two pll modes.
pic24f16ka102 family ds39927c-page 98 ? 2008-2011 microchip technology inc. the following code sequence for a clock switch is recommended: 1. disable interrupts during the osccon register unlock and write sequence. 2. execute the unlock sequence for the osccon high byte by writing 78h and 9ah to osccon<15:8> in two back-to-back instructions. 3. write new oscillator source to the noscx bits in the instruction immediately following the unlock sequence. 4. execute the unlock sequence for the osccon low byte by writing 46h and 57h to osccon<7:0> in two back-to-back instructions. 5. set the oswen bit in the instruction immediately following the unlock sequence. 6. continue to execute code that is not clock-sensitive (optional). 7. invoke an appropriate amount of software delay (cycle counting) to allow the selected oscillator and/or pll to start and stabilize. 8. check to see if oswen is ? 0 ?. if it is, the switch was successful. if oswen is still set, then check the lock bit to determine the cause of failure. the core sequence for unlocking the osccon register and initiating a clock switch is provided in example 9-1 . example 9-1: basic code sequence for clock switching 9.5 reference clock output in addition to the clko output (f osc /2) available in certain oscillator modes, the device clock in the pic24f16ka102 family devices can also be configured to provide a reference clock output signal to a port pin. this feature is available in all oscillator configurations and allows the user to select a greater range of clock submultiples to drive external devices in the application. this reference clock output is controlled by the refocon register ( register 9-4 ). setting the roen bit (refocon<15>) makes the clock signal available on the refo pin. the rodiv bits (refocon<11:8>) enable the selection of 16 different clock divider options. the rosslp and rosel bits (refocon<13:12>) control the availability of the reference output during sleep mode. the rosel bit determines if the oscillator on osc1 and osc2, or the current system clock source, is used for the reference clock output. the rosslp bit determines if the reference source is available on refo when the device is in sleep mode. to use the reference clock output in sleep mode, both the rosslp and rosel bits must be set. the device clock must also be configured for one of the primary modes (ec, hs or xt); otherwise, if the rosel bit is not also set, the oscillator on osc1 and osc2 will be powered down when the device enters sleep mode. clearing the rosel bit allows the reference output frequency to change as the system clock changes during any clock switches. ;place the new oscillator selection in w0 ;oscconh (high byte) unlock sequence mov #oscconh, w1 mov #0x78, w2 mov #0x9a, w3 mov.b w2, [w1] mov.b w3, [w1] ;set new oscillator selection mov.b wreg, oscconh ;oscconl (low byte) unlock sequence mov #oscconl, w1 mov #0x46, w2 mov #0x57, w3 mov.b w2, [w1] mov.b w3, [w1] ;start oscillator switch operation bset osccon,#0
? 2008-2011 microchip technology inc. ds39927c-page 99 pic24f16ka102 family register 9-4: refocon: reference oscillator control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 roen ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 roen: reference oscillator output enable bit 1 = reference oscillator is enabled on refo pin 0 = reference oscillator is disabled bit 14 unimplemented: read as ? 0 ? bit 13 rosslp: reference oscillator output stop in sleep bit 1 = reference oscillator continues to run in sleep 0 = reference oscillator is disabled in sleep bit 12 rosel: reference oscillator source select bit 1 = primary oscillator is used as the base clock ( 1 ) 0 = system clock is used as the base clock; base clock reflects any clock switching of the device bit 11-8 rodiv<3:0>: reference oscillator divisor select bits 1111 = base clock value divided by 32,768 1110 = base clock value divided by 16,384 1101 = base clock value divided by 8,192 1100 = base clock value divided by 4,096 1011 = base clock value divided by 2,048 1010 = base clock value divided by 1,024 1001 = base clock value divided by 512 1000 = base clock value divided by 256 0111 = base clock value divided by 128 0110 = base clock value divided by 64 0101 = base clock value divided by 32 0100 = base clock value divided by 16 0011 = base clock value divided by 8 0010 = base clock value divided by 4 0001 = base clock value divided by 2 0000 = base clock value bit 7-0 unimplemented: read as ? 0 ? note 1: the crystal oscillator must be enabled using the fosc<2:0> bits; the crystal maintains the operation in sleep mode.
pic24f16ka102 family ds39927c-page 100 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 101 pic24f16ka102 family 10.0 power-saving features the pic24f16ka102 family of devices provides the ability to manage power consumption by selectively managing clocking to the cpu and the peripherals. in general, a lower clock frequency and a reduction in the number of circuits being clocked constitutes lower consumed power. all pic24f devices manage power consumption in four different ways: ? clock frequency ? instruction-based sleep, idle and deep sleep modes ? software controlled doze mode ? selective peripheral control in software combinations of these methods can be used to selectively tailor an application?s power consumption, while still maintaining critical application features, such as timing-sensitive communications. 10.1 clock frequency and clock switching pic24f devices allow for a wide range of clock frequencies to be selected under application control. if the system clock configuratio n is not locked, users can choose low-power or high-precision oscillators by simply changing the nosc bits. the process of changing a system clock during operation, as well as limitations to the process, are discussed in more detail in section 9.0 ?oscillator configuration? . 10.2 instruction-based power-saving modes pic24f devices have two special power-saving modes that are entered through the execution of a special pwrsav instruction. sleep mode stops clock operation and halts all code execution; idle mode halts the cpu and code execution, but allows peripheral modules to continue operation. deep sleep mode stops clock operation, code execution and all peripherals except rtcc and dswdt. it also freezes i/o states and removes power to sram and flash memory. the assembly syntax of the pwrsav instruction is shown in example 10-1 . sleep and idle modes can be exited as a result of an enabled interrupt, wdt time-out or a device reset. when the device exits these modes, it is said to ?wake-up?. 10.2.1 sleep mode sleep mode includes these features: ? the system clock source is shut down. if an on-chip oscillator is used, it is turned off. ? the device current consumption will be reduced to a minimum provided that no i/o pin is sourcing current. ? the i/o pin directions and states are frozen. ? the fail-safe clock monitor does not operate during sleep mode since the system clock source is disabled. ? the lprc clock will continue to run in sleep mode if the wdt or rtcc, with lprc as the clock source, is enabled. ? the wdt, if enabled, is automatically cleared prior to entering sleep mode. ? some device features or peripherals may continue to operate in sleep mode. this includes items, such as the input change notification on the i/o ports, or peripherals that use an external clock input. any peripheral that requires the system clock source for its operation will be disabled in sleep mode. the device will wake-up from sleep mode on any of these events: ? on any interrupt source that is individually enabled ? on any form of device reset ? on a wdt time-out on wake-up from sleep, the processor will restart with the same clock source that was active when sleep mode was entered. example 10-1: pwrsav instruction syntax note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information, refer to the ?pic24f family reference manual? , ?section 39. power-saving features with deep sleep? (ds39727). note: sleep_mode and idle_mode are con- stants, defined in the assembler include file, for the selected device. pwrsav #sleep_mode ; put the device into sleep mode pwrsav #idle_mode ; put the device into idle mode bset dscon, #dsen ; enable deep sleep pwrsav #sleep_mode ; put the device into deep sleep mode
pic24f16ka102 family ds39927c-page 102 ? 2008-2011 microchip technology inc. 10.2.2 idle mode idle mode has these features: ? the cpu will stop executing instructions. ? the wdt is automatically cleared. ? the system clock source remains active. by default, all peripheral modules continue to operate normally from the system clock source, but can also be selectively disabled (see section 10.4 ?selective peripheral module control? ). ? if the wdt or fscm is enabled, the lprc will also remain active. the device will wake from idle mode on any of these events: ? any interrupt that is individually enabled ? any device reset ? a wdt time-out on wake-up from idle, the clock is re-applied to the cpu and instruction execution begins immediately, starting with the instruction following the pwrsav instruction or the first instruction in the isr. 10.2.3 interrupts coincident with power save instructions any interrupt that coincides with the execution of a pwrsav instruction will be held off until entry into sleep or idle mode has completed. the device will then wake-up from sleep or idle mode. 10.2.4 deep sleep mode in pic24f16ka102 family devices, deep sleep mode is intended to provide the lowest levels of power con- sumption available without requiring the use of external switches to completely remove all power from the device. entry into deep sleep mode is completely under software control. exit from deep sleep mode can be triggered from any of the following events: ? por event ?mclr event ? rtcc alarm (if the rtcc is present) ? external interrupt 0 ? deep sleep watchdog timer (dswdt) time-out in deep sleep mode, it is possible to keep the device real-time clock and calendar (rtcc) running without the loss of clock cycles. the device has a dedicated deep sleep brown-out reset (dsbor) and a deep sleep watchdog timer reset (dswdt) for monitoring voltage and time-out events. the dsbor and dswdt are independent of the standard bor and wdt used with other power-managed modes (sleep, idle and doze). 10.2.4.1 entering deep sleep mode deep sleep mode is entered by setting the dsen bit in the dscon register, and then executing a sleep command ( pwrsav #sleep_mode ), within one instruction cycle, to minimize the chance that deep sleep will be spuriously entered. if the pwrsav command is not given within one instruc- tion cycle, the dsen bit will be cleared by the hardware and must be set again by the software before entering deep sleep mode. the dsen bit is also automatically cleared when exiting the deep sleep mode. the sequence to enter deep sleep mode is: 1. if the application requires the deep sleep wdt, enable it and configure its clock source (see section 10.2.4.5 ?deep sleep wdt? for details). 2. if the application requires deep sleep bor, enable it by programming the dsboren configuration bit (fds<6>). 3. if the application requires wake-up from deep sleep on rtcc alarm, enable and configure the rtcc module (see section 19.0 ?real-time clock and calendar (rtcc)? for more information). 4. if needed, save any critical application context data by writing it to the dsgpr0 and dsgpr1 registers (optional). 5. enable deep sleep mode by setting the dsen bit (dscon<15>). 6. enter deep sleep mode by issuing 3 nop commands, and then a pwrsav #0 instruction. any time the dsen bit is set, all bits in the dswake register will be automatically cleared. note: to re-enter deep sleep after a deep sleep wake-up, allow a delay of at least 3 t cy after clearing the release bit.
? 2008-2011 microchip technology inc. ds39927c-page 103 pic24f16ka102 family 10.2.4.2 exiting deep sleep mode deep sleep mode exits on any one of the following events: ? por event on v dd supply. if there is no dsbor circuit to re-arm the v dd supply por circuit, the external v dd supply must be lowered to the natural arming voltage of the por circuit. ? dswdt time-out. when the dswdt timer times out, the device exits deep sleep. ? rtcc alarm (if rtcen = 1 ). ? assertion (? 0 ?) of the mclr pin. ? assertion of the int0 pin (if the interrupt was enabled before deep sleep mode was entered). the polarity configuration is used to determine the assertion level (? 0 ? or ? 1 ?) of the pin that will cause an exit from deep sleep mode. exiting from deep sleep mode requires a change on the int0 pin while in deep sleep mode. exiting deep sleep mode generally does not retain the state of the device and is equivalent to a power-on reset (por) of the device. exceptions to this include the rtcc (if present), which remains operational through the wake-up, the dsgprx registers and the dswdt bit. wake-up events that occur from the time deep sleep exits until the time the por sequence completes are ignored and are not be captured in the dswake register. the sequence for exiting deep sleep mode is: 1. after a wake-up event, the device exits deep sleep and performs a por. the dsen bit is cleared automatically. code execution resumes at the reset vector. 2. to determine if the device exited deep sleep, read the deep sleep bit, dpslp (rcon<10>). this bit will be set if there was an exit from deep sleep mode; if the bit is set, clear it. 3. determine the wake-up source by reading the dswake register. 4. determine if a dsbor event occurred during deep sleep mode by reading the dsbor bit (dscon<1>). 5. if application context data has been saved, read it back from the dsgpr0 and dsgpr1 registers. 6. clear the release bit (dscon<0>). 10.2.4.3 saving context data with the dsgpr0/dsgpr1 registers as exiting deep sleep mode causes a por, most special function registers reset to their default por values. in addition, because v ddcore power is not supplied in deep sleep mode, information in data ram may be lost when exiting this mode. applications which require critical data to be saved prior to deep sleep may use the deep sleep general purpose registers, dsgpr0 and dsgpr1, or data eeprom (if available). unlike other sfrs, the contents of these registers are preserved while the device is in deep sleep mode. after exiting deep sleep, software can restore the data by reading the registers and clearing the release bit (dscon<0>). 10.2.4.4 i/o pins during deep sleep during deep sleep, the general purpose i/o pins retain their previous states and the secondary oscillator (sosc) will remain running, if enabled. pins that are configured as inputs (trisx bit set), prior to entry into deep sleep, remain high-impedance during deep sleep. pins that are configured as outputs (trisx bit clear), prior to entry into deep sleep, remain as output pins during deep sleep. while in this mode, they con- tinue to drive the output level determined by their corresponding latx bit at the time of entry into deep sleep. once the device wakes back up, all i/o pins continue to maintain their previous states, even after the device has finished the por sequence and is executing appli- cation code again. pins configured as inputs during deep sleep remain high-impedance and pins config- ured as outputs continue to drive their previous value. after waking up, the tris and lat registers, and the soscen bit (osccon<1>) are reset. if firmware modifies any of these bits or registers, the i/o will not immediately go to the newly configured states. once the firmware clears the release bit (dscon<0>), the i/o pins are ?released?. this causes the i/o pins to take the states configured by their respective tris and lat bit values. this means that keeping the sosc running after waking up requires the soscen bit to be set before clearing release. if the deep sleep bor (dsbor) is enabled, and a dsbor or a true por event occurs during deep sleep, the i/o pins will be immediately released, similar to clearing the release bit. all previous state infor- mation will be lost, including the general purpose dsgpr0 and dsgpr1 contents. if a mclr reset event occurs during deep sleep, the dsgprx, dscon and dswake registers will remain valid, and the release bit will remain set. the state of the sosc will also be retained. the i/o pins, how- ever, will be reset to their mclr reset state. since release is still set, changes to the soscen bit (osccon<1>) cannot take effect until the release bit is cleared. in all other deep sleep wake-up cases, application firmware must clear the release bit in order to reconfigure the i/o pins. note: any interrupt pending when entering deep sleep mode is cleared,
pic24f16ka102 family ds39927c-page 104 ? 2008-2011 microchip technology inc. 10.2.4.5 deep sleep wdt to enable the dswdt in deep sleep mode, program the configuration bit, dswdten (fds<7>). the device watchdog timer (wdt) need not be enabled for the dswdt to function. entry into deep sleep mode automatically resets the dswdt. the dswdt clock source is selected by the dswdtosc configuration bit (fds<4>). the post- scaler options are programmed by the dswdtps<3:0> configuration bits (fds<3:0>). the minimum time-out period that can be achieved is 2.1 ms and the maximum is 25.7 days. for more details on the fds configuration register and dswdt configuration options, refer to section 26.0 ?special features? . 10.2.4.6 switching clocks in deep sleep mode both the rtcc and the dswdt may run from either sosc or the lprc clock source. this allows both the rtcc and dswdt to run without requiring both the lprc and sosc to be enabled together, reducing power consumption. running the rtcc from lprc will result in a loss of accuracy in the rtcc of approximately 5 to 10%. if a more accurate rtcc is required, it must be run from the sosc clock source. the rtcc clock source is selected with the rtcosc configuration bit (fds<5>). under certain circumstances, it is possible for the dswdt clock source to be off when entering deep sleep mode. in this case, the clock source is turned on automatically (if dswdt is enabled), without the need for software intervention. however, this can cause a delay in the start of the dswdt counters. in order to avoid this delay when using sosc as a clock source, the application can activate sosc prior to entering deep sleep mode. 10.2.4.7 checking and clearing the status of deep sleep upon entry into deep sleep mode, the status bit dpslp (rcon<10>), becomes set and must be cleared by software. on power-up, the software should read this status bit to determine if the reset was due to an exit from deep sleep mode and clear the bit if it is set. of the four possible combinations of dpslp and por bit states, three cases can be considered: ? both the dpslp and por bits are cleared. in this case, the reset was due to some event other than a deep sleep mode exit. ? the dpslp bit is clear, but the por bit is set. this is a normal por. ? both the dpslp and por bits are set. this means that deep sleep mode was entered, the device was powered down and deep sleep mode was exited. 10.2.4.8 power-on resets ( pors ) v dd voltage is monitored to produce pors. since exit- ing from deep sleep functionally looks like a por, the technique described in section 10.2.4.7 ?checking and clearing the status of deep sleep? should be used to distinguish between deep sleep and a true por event. when a true por occurs, the entire device, including all deep sleep logic (deep sleep registers, rtcc, dswdt, etc.) is reset. 10.2.4.9 summary of deep sleep sequence to review, these are the necessary steps involved in invoking and exiting deep sleep mode: 1. device exits reset and begins to execute its application code. 2. if dswdt functionality is required, program the appropriate configuration bit. 3. select the appropriate clock(s) for the dswdt and rtcc (optional). 4. enable and configure the dswdt (optional). 5. enable and configure the rtcc (optional). 6. write context data to the dsgprx registers (optional). 7. enable the int0 interrupt (optional). 8. set the dsen bit in the dscon register. 9. enter deep sleep by issuing a pwrsv #sleep_mode command. 10. device exits deep sleep when a wake-up event occurs. 11. the dsen bit is automatically cleared. 12. read and clear the dpslp status bit in rcon, and the dswake status bits. 13. read the dsgprx registers (optional). 14. once all state related configurations are complete, clear the release bit. 15. application resumes normal operation.
? 2008-2011 microchip technology inc. ds39927c-page 105 pic24f16ka102 family register 10-1: dscon: deep sleep control register ( 1 ) r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 dsen ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/c-0, hs ? ? ? ? ? ? dsbor ( 2 ) release bit 7 bit 0 legend: c = clearable bit hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 dsen: deep sleep enable bit 1 = enters deep sleep on execution of pwrsav #0 0 = enters normal sleep on execution of pwrsav #0 bit 14-2 unimplemented: read as ? 0 ? bit 1 dsbor: deep sleep bor event bit ( 2 ) 1 = the dsbor was active and a bor event was detected during deep sleep 0 = the dsbor was not active, or was active but did not detect a bor event during deep sleep bit 0 release: i/o pin state release bit 1 = upon waking from deep sleep, i/o pins maintain their states previous to deep sleep entry 0 = release i/o pins from their state previous to deep sleep entry, and allow their respective tris and lat bits to control their states note 1: all register bits are reset only in the case of a por event outside of deep sleep mode. 2: unlike all other events, a deep sleep bor event will not cause a wake-up from deep sleep; this re-arms por.
pic24f16ka102 family ds39927c-page 106 ? 2008-2011 microchip technology inc. register 10-2: dswake: deep sleep wake-up source register ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0, hs ? ? ? ? ? ? ?dsint0 bit 15 bit 8 r/w-0, hs u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs u-0 r/w-0, hs dsflt ? ? dswdt dsrtcc dsmclr ? dspor ( 2 , 3 ) bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 dsint0: interrupt-on-change bit 1 = interrupt-on-change was asserted during deep sleep 0 = interrupt-on-change was not asserted during deep sleep bit 7 dsflt: deep sleep fault detected bit 1 = a fault occurred during deep sleep, and some deep sleep configuration settings may have been corrupted 0 = no fault was detected during deep sleep bit 6-5 unimplemented: read as ? 0 ? bit 4 dswdt: deep sleep watchdog timer time-out bit 1 = the deep sleep watchdog timer timed out during deep sleep 0 = the deep sleep watchdog timer did not time out during deep sleep bit 3 dsrtcc: real-time clock and calendar alarm bit 1 = the real-time clock and calendar triggered an alarm during deep sleep 0 = the real-time clock and calendar did not trigger an alarm during deep sleep bit 2 dsmclr: mclr event bit 1 = the mclr pin was active and was asserted during deep sleep 0 = the mclr pin was not active, or was active, but not asserted during deep sleep bit 1 unimplemented: read as ? 0 ? bit 0 dspor: power-on reset event bit ( 2 , 3 ) 1 = the v dd supply por circuit was active and a por event was detected 0 = the v dd supply por circuit was not active, or was active but did not detect a por event note 1: all register bits are cleared when the dscon bit is set. 2: all register bits are reset only in the case of a por event outside deep sleep mode, except bit, dspor, which does not reset on a por event that is caused due to a deep sleep exit. 3: unlike the other bits in this register, this bit can be set outside of deep sleep.
? 2008-2011 microchip technology inc. ds39927c-page 107 pic24f16ka102 family 10.3 doze mode generally, changing clock speed and invoking one of the power-saving modes are the preferred strategies for reducing power consumption. there may be circumstances, however, where this is not practical. for example, it may be necessary for an application to maintain uninterrupted synchronous communication, even while it is doing nothing else. reducing system clock speed may introduce communication errors, while using a power-saving mode may stop communications completely. doze mode is a simple and effective alternative method to reduce power consumption while the device is still executing code. in this mode, the system clock continues to operate from the same source and at the same speed. peripheral modules continue to be clocked at the same speed while the cpu clock speed is reduced. synchronization between the two clock domains is maintained, allowing the peripherals to access the sfrs while the cpu executes code at a slower rate. doze mode is enabled by setting the dozen bit (clkdiv<11>). the ratio between peripheral and core clock speed is determined by the doze<2:0> bits (clkdiv<14:12>). there are eight possible configurations, from 1:1 to 1:128, with 1:1 being the default. it is also possible to use doze mode to selectively reduce power consumption in event driven applications. this allows clock-sensitive functions, such as synchronous communications, to continue without interruption while the cpu idles, waiting for something to invoke an interrupt routine. enabling the automatic return to full-speed cpu operation on interrupts is enabled by set- ting the roi bit (clkdiv<15>). by default, interrupt events have no effect on doze mode operation. 10.4 selective peripheral module control idle and doze modes allow users to substantially reduce power consumption by slowing or stopping the cpu clock. even so, peripheral modules still remain clocked, and thus, consume power. there may be cases where the application needs what these modes do not provide: the allocation of power resources to cpu processing with minimal power consumption from the peripherals. pic24f devices address this requirement by allowing peripheral modules to be selectively disabled, reducing or eliminating their power consumption. this can be done with two control bits: ? the peripheral enable bit, generically named, ?xxxen?, located in the module?s main control sfr. ? the peripheral module disable (pmd) bit, generically named, ?xxxmd?, located in one of the pmd control registers. both bits have similar functions in enabling or disabling its associated module. setting the pmd bit for a module disables all clock sources to that module, reducing its power consumption to an absolute minimum. in this state, the control and status registers associated with the peripheral will also be disabled, so writes to those registers will have no effect and read values will be invalid. many peripheral modules have a corresponding pmd bit. in contrast, disabling a module by clearing its xxxen bit disables its functionality, but leaves its registers available to be read and written to. power consumption is reduced, but not by as much as the pmd bits are used. most peripheral modules have an enable bit; exceptions include capture, compare and rtcc. to achieve more selective power savings, peripheral modules can also be selectively disabled when the device enters idle mode. this is done through the control bit of the generic name format, ?xxxidl?. by default, all modules that can operate during idle mode will do so. using the disable on idle feature disables the module while in idle mode, allowing further reduction of power consumption during idle mode, enhancing power savings for extremely critical power applications.
pic24f16ka102 family ds39927c-page 108 ? 2008-2011 microchip technology inc. register 10-3: pmd1: peripheral module disable register 1 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 ? ? t3md t2md t1md ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 r/w-0 i2c1md u2md u1md ? spi1md ? ? adc1md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 t3md: timer3 module disable bit 1 = timer3 module is disabled. all timer3 registers are held in reset and are not writable. 0 = timer3 module is enabled bit 12 t2md: timer2 module disable bit 1 = timer2 module is disabled. all timer2 registers are held in reset and are not writable. 0 = timer2 module is enabled bit 11 t1md: timer1 module disable bit 1 = timer1 module is disabled. all timer1 registers are held in reset and are not writable. 0 = timer1 module is enabled bit 10-8 unimplemented: read as ? 0 ? bit 7 i2c1md: i2c1 module disable bit 1 = i2c1 module is disabled. all i2c1 registers are held in reset and are not writable. 0 = i2c1 module is enabled bit 6 u2md: uart2 module disable bit 1 = uart2 module is disabled. all uart2 registers are held in reset and are not writable. 0 = uart2 module is enabled bit 5 u1md: uart1 module disable bit 1 = uart1 module is disabled. all uart1 registers are held in reset and are not writable. 0 = uart1 module is enabled bit 4 unimplemented: read as ? 0 ? bit 3 spi1md: spi1 module disable bit 1 = spi1 module is disabled. all spi1 registers are held in reset and are not writable. 0 = spi1 module is enabled bit 2-1 unimplemented: read as ? 0 ? bit 0 adc1md: a/d module disable bit 1 = a/d module is disabled. all a/d registers are held in reset and are not writable. 0 = a/d module is enabled
? 2008-2011 microchip technology inc. ds39927c-page 109 pic24f16ka102 family register 10-4: pmd2: peripheral module disable register 2 u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ? i2c1md bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ? oc1md bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 i2c1md: input capture 1 module disable bit 1 = input capture 1 module is disabled. all input capture registers are held in reset and are not writable. 0 = input capture 1 module is writable bit 7-1 unimplemented: read as ? 0 ? bit 0 oc1md: input compare 1 module disable bit 1 = output compare 1 module is disabled. all output compare registers are held in reset and are not writable. 0 = output compare 1 module is writable
pic24f16ka102 family ds39927c-page 110 ? 2008-2011 microchip technology inc. register 10-5: pmd3: peripheral module disable register 3 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 u-0 ? ? ? ? ? cmpmd rtccmd ? bit 15 bit 8 r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 crcmd ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-11 unimplemented: read as ? 0 ? bit 10 cmpmd: comparator module disable bit 1 = comparator module is disabled. all comparator module registers are held in reset and are not writable. 0 = comparator module is enabled bit 9 rtccmd: rtcc module disable bit 1 = rtcc module is disabled. all rtcc module registers are held in reset and are not writable. 0 = rtcc module is enabled bit 8 unimplemented: read as ? 0 ? bit 7 crcmd: crc module disable bit 1 = crc module is disabled. all crc registers are held in reset and are not writable. 0 = crc module is enabled bit 6-0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 111 pic24f16ka102 family register 10-6: pmd4: peripheral module disable register 4 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 ? ? ? eemd refomd ctmumd hlvdmd ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-5 unimplemented: read as ? 0 ? bit 4 eemd: eeprom memory module disable bit 1 = disable eeprom memory flash panel, minimizing current consumption 0 = eeprom memory is disabled bit 3 refomd: reference oscillator module disable bit 1 = reference oscillator module is disabled. all reference oscillator registers are held in reset and are not writable 0 = reference oscillator module is enabled bit 2 ctmumd: ctmu module disable bit 1 = ctmu module is disabled. all ctmu registers are held in reset and are not writable. 0 = ctmu module is enabled bit 1 hlvdmd: hlvd module disable bit 1 = hlvd module is disabled. all hlvd registers are held in reset and are not writable. 0 = hlvd module is enabled bit 0 unimplemented: read as ? 0 ?
pic24f16ka102 family ds39927c-page 112 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 113 pic24f16ka102 family 11.0 i/o ports all of the device pins (except v dd and v ss ) are shared between the peripherals and the parallel i/o ports. all i/o input ports feature schmitt trigger inputs for improved noise immunity. 11.1 parallel i/o (pio) ports a parallel i/o port that shares a pin with a peripheral is, in general, subservient to the peripheral. the peripheral?s output buffer data and control signals are provided to a pair of multiplexers. the multiplexers select whether the peripheral or the associated port has ownership of the output data and control signals of the i/o pin. the logic also prevents ?loop through?, in which a port?s digital output can drive the input of a peripheral that shares the same pin. figure 11-1 displays how ports are shared with other peripherals and the associated i/o pin to which they are connected. when a peripheral is enabled and the peripheral is actively driving an associated pin, the use of the pin as a general purpose output pin is disabled. the i/o pin may be read, but the output driver for the parallel port bit will be disabled. if a peripheral is enabled, but the peripheral is not actively driving a pin, that pin may be driven by a port. all port pins have three registers directly associated with their operation as digital i/o. the data direction register (trisx) determines whether the pin is an input or an output. if the data direction bit is a ? 1 ?, then the pin is an input. all port pins are defined as inputs after a reset. reads from the data latch register (latx), read the latch. writes to the latch, write the latch. reads from the port (portx), read the port pins, while writes to the port pins, write the latch. any bit and its associated data and control registers that are not valid for a particular device will be disabled. that means the corresponding latx and trisx registers, and the port pin will read as zeros. when a pin is shared with another peripheral or function that is defined as an input only, it is nevertheless regarded as a dedicated port because there is no other competing source of outputs. figure 11-1: block diagram of a typical shared port structure note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the i/o ports, refer to the ?pic24f family refer- ence manual? , section 12. ?i/o ports with peripheral pin select (pps)? (ds39711). note that the pic24f16ka102 family devices do not support peripheral pin select features. note: the i/o pins retain their state during deep sleep. they will retain this state at wake-up until the software restore bit (release) is cleared. q d ck wr lat + tris latch i/o pin wr port data bus q d ck data latch read port read tris 1 0 1 0 wr tris peripheral output data peripheral input data i/o peripheral module peripheral output enable pio module output multiplexers output data input data peripheral module enable read lat output enable
pic24f16ka102 family ds39927c-page 114 ? 2008-2011 microchip technology inc. 11.1.1 open-drain configuration in addition to the port, lat and tris registers for data control, each port pin can also be individually configured for either digital or open-drain output. this is controlled by the open-drain control register, odcx, associated with each port. setting any of the bits configures the corresponding pin to act as an open-drain output. the maximum open-drain voltage allowed is the same as the maximum v ih specification. 11.2 configuring analog port pins the use of the ad1pcfg and tris register controls the operation of the a/d port pins. the port pins that are desired as analog inputs must have their corresponding tris bit set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. when reading the port register, all pins configured as analog input channels will read as cleared (a low level). analog levels on any pin that is defined as a digital input (including the anx pins) may cause the input buffer to consume current that exceeds the device specifications. 11.2.1 i/o port write/read timing one instruction cycle is required between a port direction change or port write operation and a read operation of the same port. typically, this instruction would be a nop . 11.3 input change notification the input change notification function of the i/o ports allows the pic24f16ka102 family of devices to generate interrupt requests to the processor in response to a change-of-state (cos) on selected input pins. this feature is capable of detecting input change-of-states even in sleep mode, when the clocks are disabled. depending on the device pin count, there are up to 23 external signals (cn0 through cn22) that may be selected (enabled) for generating an interrupt request on a change-of-state. there are six control registers associated with the cn module. the cnen1 and cnen2 registers contain the interrupt enable control bits for each of the cn input pins. setting any of these bits enables a cn interrupt for the corresponding pins. each cn pin also has a weak pull-up/pull-down connected to it. the pull-ups act as a current source that is connected to the pin and the pull-downs act as a current sink to eliminate the need for external resistors when push button or keypad devices are connected. on any pin, only the pull-up resistor or the pull-down resistor should be enabled, but not both of them. if the push button or the keypad is connected to v dd , enable the pull-down, or if they are connected to v ss , enable the pull-up resistors. the pull-ups are enabled separately using the cnpu1 and cnpu2 registers, which contain the control bits for each of the cn pins. setting any of the control bits enables the weak pull-ups for the corresponding pins. the pull-downs are enabled separately using the cnpd1 and cnpd2 registers, which contain the control bits for each of the cn pins. setting any of the control bits enables the weak pull-downs for the corresponding pins. when the internal pull-up is selected, the pin uses v dd as the pull-up source voltage. when the internal pull-down is selected, the pins are pulled down to v ss by an internal resistor. make sure that there is no external pull-up source/pull-down sink when the internal pull-ups/pull-downs are enabled. example 11-1: port write/read example note: pull-ups and pull-downs on change notification pins should always be disabled whenever the port pin is configured as a digital output. mov 0xff00, w0; //configure portb<15:8> as inputs and portb<7:0> as outputs mov w0, trisbb; nop; //delay 1 cycle btss portb, #13; //next instruction equivalent ?c? code trisb = 0xff00; //configure portb<15:8> as inputs and portb<7:0> as outputs nop(); //delay 1 cycle if(portbbits.rb13 == 1) // execute following code if portb pin 13 is set. { }
? 2008-2011 microchip technology inc. ds39927c-page 115 pic24f16ka102 family 12.0 timer1 the timer1 module is a 16-bit timer which can serve as the time counter for the real-time clock (rtc), or operate as a free-running, interval timer/counter. timer1 can operate in three modes: ?16-bit timer ? 16-bit synchronous counter ? 16-bit asynchronous counter timer1 also supports these features: ? timer gate operation ? selectable prescaler settings ? timer operation during cpu idle and sleep modes ? interrupt on 16-bit period register match or falling edge of external gate signal figure 12-1 presents a block diagram of the 16-bit timer1 module. to configure timer1 for operation: 1. set the ton bit (= 1 ). 2. select the timer prescaler ratio using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. set or clear the tsync bit to configure synchronous or asynchronous operation. 5. load the timer period value into the pr1 register. 6. if interrupts are required, set the interrupt enable bit, t1ie. use the priority bits, t1ip<2:0>, to set the interrupt priority. figure 12-1: 16-bit time r1 module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on timers, refer to the ?pic24f family refer- ence manual? , section 14. ?timers? (ds39704). ton sync sosci sosco/ pr1 set t1if equal comparator tmr1 reset soscen 1 0 tsync q qd ck tckps<1:0> prescaler 1, 8, 64, 256 2 tgate t cy 1 0 t1ck tcs 1x 01 tgate 00 gate sync
pic24f16ka102 family ds39927c-page 116 ? 2008-2011 microchip technology inc. register 12-1: t1con: ti mer1 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ton ?tsidl ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 u-0 ? tgate tckps1 tckps0 ?tsynctcs ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer1 on bit 1 = starts 16-bit timer1 0 = stops 16-bit timer1 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-7 unimplemented: read as ? 0 ? bit 6 tgate: timer1 gated time accumulation enable bit when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation is enabled 0 = gated time accumulation is disabled bit 5-4 tckps<1:0>: timer1 input clock prescale select bits 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3 unimplemented: read as ? 0 ? bit 2 tsync: timer1 external clock input synchronization select bit when tcs = 1 : 1 = synchronize external clock input 0 = do not synchronize external clock input when tcs = 0 : this bit is ignored. bit 1 tcs: timer1 clock source select bit 1 = external clock from t1ck pin (on the rising edge) 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 117 pic24f16ka102 family 13.0 timer2/3 the timer2/3 module is a 32-bit timer, which can also be configured as two independent 16-bit timers with selectable operating modes. as a 32-bit timer, timer2/3 operates in three modes: ? two independent 16-bit timers (timer2 and timer3) with all 16-bit operating modes (except asynchronous counter mode) ? single 32-bit timer ? single 32-bit synchronous counter they also support these features: ? timer gate operation ? selectable prescaler settings ? timer operation during idle and sleep modes ? interrupt on a 32-bit period register match ? a/d event trigger individually, both of the 16-bit timers can function as synchronous timers or counters. they also offer the features listed above, except for the a/d event trigger (this is implemented only with timer3). the operating modes and enabled features are determined by setting the appropriate bit(s) in the t2con and t3con registers. t2con and t3con are provided in generic form in register 13-1 and register 13-2 , respectively. for 32-bit timer/counter operation, timer2 is the least significant word (lsw) and timer3 is the most significant word (msw) of the 32-bit timer. to configure timer2/3 for 32-bit operation: 1. set the t32 bit (t2con<3> = 1 ). 2. select the prescaler ratio for timer2 using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. load the timer period value. pr3 will contain the msw of the value while pr2 contains the lsw. 5. if interrupts are required, set the interrupt enable bit, t3ie. use the priority bits, t3ip<2:0>, to set the interrupt priority. while timer2 controls the timer, the interrupt appears as a timer3 interrupt. 6. set the ton bit (= 1 ). the timer value, at any point, is stored in the register pair, tmr<3:2>. tmr3 always contains the msw of the count, while tmr2 contains the lsw. to configure any of the timers for individual 16-bit operation: 1. clear the t32 bit in t2con<3>. 2. select the timer prescaler ratio using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. load the timer period value into the prx register. 5. if interrupts are required, set the interrupt enable bit, txie; use the priority bits, txip<2:0>, to set the interrupt priority. 6. set the ton bit (txcon<15> = 1 ). note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on timers, refer to the ?pic24f family refer- ence manual? , section 14. ?timers? (ds39704). note: for 32-bit operation, t3con control bits are ignored. only t2con control bits are used for setup and control. timer2 clock and gate inputs are utilized for the 32-bit timer modules, but an interrupt is generated with the timer3 interrupt flags.
pic24f16ka102 family ds39927c-page 118 ? 2008-2011 microchip technology inc. figure 13-1: timer2/3 (32-bit) block diagram tmr3 tmr2 set t3if equal comparator pr3 pr2 reset lsb msb note 1: the 32-bit timer configuration (t32) bit must be set for 32-bit timer/counter operation. all control bits are respective to the t2con register. data bus<15:0> tmr3hld read tmr2 (1) write tmr2 (1) 16 16 16 q qd ck tgate 0 1 ton tckps<1:0> prescaler 1, 8, 64, 256 2 t cy tcs tgate gate t2ck sync a/d event trigger sync 1x 01 00 16
? 2008-2011 microchip technology inc. ds39927c-page 119 pic24f16ka102 family figure 13-2: timer2 (16-bi t synchronous) block diagram figure 13-3: timer3 (16-bi t synchronous) block diagram ton tckps<1:0> prescaler 1, 8, 64, 256 2 t cy tcs 1x 01 tgate 00 gate t2ck sync pr2 set t2if equal comparator tmr2 reset q qd ck tgate 1 0 sync ton tckps<1:0> 2 t cy tcs 1x 01 tgate 00 t3ck pr3 set t3if equal comparator tmr3 reset q qd ck tgate 1 0 a/d event trigger prescaler 1, 8, 64, 256 sync
pic24f16ka102 family ds39927c-page 120 ? 2008-2011 microchip technology inc. register 13-1: t2con: ti mer2 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ton ?tsidl ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 ? tgate tckps1 tckps0 t32 ( 1 ) ?tcs ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer2 on bit when t2con<3> = 1 : 1 = starts 32-bit timer2/3 0 = stops 32-bit timer2/3 when t2con<3> = 0 : 1 = starts 16-bit timer2 0 = stops 16-bit timer2 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-7 unimplemented: read as ? 0 ? bit 6 tgate: timer2 gated time accumulation enable bit when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation is enabled 0 = gated time accumulation is disabled bit 5-4 tckps<1:0>: timer2 input clock prescale select bits 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3 t32: 32-bit timer mode select bit ( 1 ) 1 = timer2 and timer3 form a single 32-bit timer 0 = timer2 and timer3 act as two 16-bit timers bit 2 unimplemented: read as ? 0 ? bit 1 tcs: timer2 clock source select bit 1 = external clock from pin, t2ck (on the rising edge) 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ? note 1: in 32-bit mode, the t3con control bits do not affect 32-bit timer operation.
? 2008-2011 microchip technology inc. ds39927c-page 121 pic24f16ka102 family register 13-2: t3con: ti mer3 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ton ( 1 ) ?tsidl ( 1 ) ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 u-0 ?tgate ( 1 ) tckps1 ( 1 ) tckps0 ( 1 ) ? ?tcs ( 1 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer3 on bit ( 1 ) 1 = starts 16-bit timer3 0 = stops 16-bit timer3 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit ( 1 ) 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-7 unimplemented: read as ? 0 ? bit 6 tgate: timer3 gated time accumulation enable bit ( 1 ) when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation is enabled 0 = gated time accumulation is disabled bit 5-4 tckps<1:0>: timer3 input clock prescale select bits ( 1 ) 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3-2 unimplemented: read as ? 0 ? bit 1 tcs: timer3 clock source select bit ( 1 ) 1 = external clock from the t3ck pin (on the rising edge) 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ? note 1: when 32-bit operation is enabled (t2con<3> = 1 ), these bits have no effect on timer3 operation; all timer functions are set through t2con.
pic24f16ka102 family ds39927c-page 122 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 123 pic24f16ka102 family 14.0 input capture the input capture module is used to capture a timer value from one of two selectable time bases upon an event on an input pin. the input capture features are quite useful in applications requiring frequency (time period) and pulse measurement. figure 14-1 depicts a simplified block diagram of the input capture module. the pic24f16ka102 family devices have one input capture channel. the input capture module has multiple operating modes, which are selected via the ic1con register. the operating modes include: ? capture timer value on every falling edge of input applied at the ic1 pin ? capture timer value on every rising edge of input applied at the ic1 pin ? capture timer value on every 4 th rising edge of input applied at the ic1 pin ? capture timer value on every 16 th rising edge of input applied at the ic1 pin ? capture timer value on every rising and every falling edge of input applied at the ic1 pin ? device wake-up from capture pin during cpu sleep and idle modes the input capture module has a four-level fifo buffer. the number of capture events required to generate a cpu interrupt can be selected by the user. figure 14-1: input capture block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on input capture, refer to the ?pic24f family reference manual? , section 15. ?input capture? (ds39701). ic1buf ic1 pin icm<2:0> (ic1con<2:0>) mode select 3 10 set flag ic1if (in ifsn register) tmry tmrx edge detection logic 16 16 fifo r/w logic ici<1:0> icov, icbne (ic1con<4:3>) ic1con interrupt logic system bus from 16-bit timers ictmr (ic1con<7>) prescaler counter (1, 4, 16) clock synchronizer
pic24f16ka102 family ds39927c-page 124 ? 2008-2011 microchip technology inc. 14.1 input capture registers register 14-1: ic1con: input capture 1 control register u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ?icsidl ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r-0, hc r-0, hc r/w-0 r/w-0 r/w-0 ictmr ici1 ici0 icov icbne icm2 icm1 icm0 bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 icsidl: input capture 1 module stop in idle control bit 1 = input capture module will halt in cpu idle mode 0 = input capture module will continue to operate in cpu idle mode bit 12-8 unimplemented: read as ? 0 ? bit 7 ictmr: input capture 1 timer select bit 1 = tmr2 contents are captured on capture event 0 = tmr3 contents are captured on capture event bit 6-5 ici<1:0>: select number of captures per interrupt bits 11 = interrupt on every fourth capture event 10 = interrupt on every third capture event 01 = interrupt on every second capture event 00 = interrupt on every capture event bit 4 icov: input capture 1 overflow status flag bit (read-only) 1 = input capture overflow occurred 0 = no input capture overflow occurred bit 3 icbne: input capture 1 buffer empty status bit (read-only) 1 = input capture buffer is not empty, at least one more capture value can be read 0 = input capture buffer is empty bit 2-0 icm<2:0>: input capture 1 mode select bits 111 = input capture functions as interrupt pin only when device is in sleep or idle mode (rising edge detect only, all other control bits are not applicable) 110 = unused (module is disabled) 101 = capture mode, every 16th rising edge 100 = capture mode, every 4th rising edge 011 = capture mode, every rising edge 010 = capture mode, every falling edge 001 = capture mode, every edge (rising and falling) ? ici<1:0> bits do not control interrupt generation for this mode 000 = input capture module is turned off
? 2008-2011 microchip technology inc. ds39927c-page 125 pic24f16ka102 family 15.0 output compare 15.1 setup for single output pulse generation when the ocm control bits (oc1con<2:0>) are set to ? 100 ?, the selected output compare channel initializes the oc1 pin to the low state and generates a single output pulse. to generate a single output pulse, the following steps are required (these steps assume the timer source is initially turned off, but this is not a requirement for the module operation): 1. determine the instruction clock cycle time. take into account the frequency of the external clock to the timer source (if one is used) and the timer prescaler settings. 2. calculate time to the rising edge of the output pulse relative to the tmry start value (0000h). 3. calculate the time to the falling edge of the pulse based on the desired pulse width and the time to the rising edge of the pulse. 4. write the values computed in steps 2 and 3 above into the output compare 1 register, oc1r, and the output compare 1 secondary register, oc1rs, respectively. 5. set timer period register, pry, to value equal to or greater than the value in oc1rs, the output compare 1 secondary register. 6. set the ocm bits to ? 100 ? and the octsel (oc1con<3>) bit to the desired timer source. the oc1 pin state will now be driven low. 7. set the ton (tycon<15>) bit to ? 1 ?, which enables the compare time base to count. 8. upon the first match between tmry and oc1r, the oc1 pin will be driven high. 9. when the incrementing timer, tmry, matches the output compare 1 secondary register, oc1rs, the second and trailing edge (high-to-low) of the pulse is driven onto the oc1 pin. no additional pulses are driven onto the oc1 pin and it remains low. as a result of the second compare match event, the oc1if inter- rupt flag bit is set, which will result in an interrupt if it is enabled, by setting the oc1ie bit. for further information on peripheral interrupts, refer to section 8.0 ?interrupt controller? . 10. to initiate another single pulse output, change the timer and compare register settings, if needed, and then issue a write to set the ocm bits to ? 100 ?. disabling and re-enabling of the timer and clearing the tmry register are not required, but may be advantageous for defining a pulse from a known event time boundary. the output compare module does not have to be disabled after the falling edge of the output pulse. another pulse can be initiated by rewriting the value of the oc1con register. 15.2 setup for continuous output pulse generation when the ocm control bits (oc1con<2:0>) are set to ? 101 ?, the selected output compare channel initializes the oc1 pin to the low state and generates output pulses on each and every compare match event. for the user to configure the module for the generation of a continuous stream of output pulses, the following steps are required (these steps assume the timer source is initially turned off, but this is not a requirement for the module operation): 1. determine the instruction clock cycle time. take into account the frequency of the external clock to the timer source (if one is used) and the timer prescaler settings. 2. calculate time to the rising edge of the output pulse relative to the tmry start value (0000h). 3. calculate the time to the falling edge of the pulse based on the desired pulse width and the time to the rising edge of the pulse. 4. write the values computed in step 2 and 3 above into the output compare 1 register, oc1r, and the output compare 1 secondary register, oc1rs, respectively. 5. set the timer period register, pry, to a value equal to or greater than the value in oc1rs. 6. set the ocm bits to ? 101 ? and the octsel bit to the desired timer source. the oc1 pin state will now be driven low. 7. enable the compare time base by setting the ton (tycon<15>) bit to ? 1 ?. 8. upon the first match between tmry and oc1r, the oc1 pin will be driven high. 9. when the compare time base, tmry, matches the oc1rs, the second and trailing edge (high-to-low) of the pulse is driven onto the oc1 pin. 10. as a result of the second compare match event, the oc1if interrupt flag bit is set. 11. when the compare time base and the value in its respective timer period register match, the tmry register resets to 0x0000 and resumes counting. 12. steps 8 through 11 are repeated and a continu- ous stream of pulses is generated indefinitely. the oc1if flag is set on each oc1rs/tmry compare match event. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on output compare, refer to the ?pic24f family reference manual? , section 16. ?output compare? (ds39706).
pic24f16ka102 family ds39927c-page 126 ? 2008-2011 microchip technology inc. 15.3 pulse-width modulation (pwm) mode the following steps should be taken when configuring the output compare module for pwm operation: 1. set the pwm period by writing to the selected timer period register (pry). 2. set the pwm duty cycle by writing to the oc1rs register. 3. write the oc1r register with the initial duty cycle. 4. enable interrupts, if required, for the timer and output compare modules. the output compare interrupt is required for pwm fault pin utilization. 5. configure the output compare module for one of two pwm operation modes by writing to the output compare mode bits, ocm<2:0> (oc1con<2:0>). 6. set the tmry prescale value and enable the time base by setting ton (txcon<15>) = 1 . 15.3.1 pwm period the pwm period is specified by writing to pry, the timer period register. the pwm period can be calculated using equation 15-1 . equation 15-1: calculating the pwm period ( 1 ) 15.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the oc1rs register. the oc1rs register can be written to at any time, but the duty cycle value is not latched into oc1r until a match between pry and tmry occurs (i.e., the period is complete). this provides a double buffer for the pwm duty cycle and is essential for glitchless pwm operation. in pwm mode, oc1r is a read-only register. some important boundary parameters of the pwm duty cycle include: ? if the output compare 1 register, oc1r, is loaded with 0000h, the oc1 pin will remain low (0% duty cycle). ? if oc1r is greater than pry (timer period register), the pin will remain high (100% duty cycle). ? if oc1r is equal to pry, the oc1 pin will be low for one time base count value and high for all other count values. see example 15-1 for pwm mode timing details. table 15-1 provides an example of pwm frequencies and resolutions for a device operating at 10 mips. equation 15-2: calculation for maximum pwm resolution ( 1 ) note: the oc1r register should be initialized before the output compare module is first enabled. the oc1r register becomes a read-only duty cycle register when the module is operated in the pwm modes. the value held in oc1r will become the pwm duty cycle for the first pwm period. the contents of the output compare 1 secondary register, oc1rs, will not be transferred into oc1r until a time base period match occurs. note: a pry value of n will produce a pwm period of n + 1 time base count cycles. for example, a value of 7, written into the pry register, will yield a period consisting of 8 time base cycles. pwm period = [(pry) + 1] ? t cy ? (timer prescale value) pwm frequency = 1/[pwm period] where: note 1: based on t cy = 2 * t osc ; doze mode and pll are disabled. ( ) maximum pwm resolution (bits) = f cy f pwm ? (timer prescale value) log 10 log 10 (2) bits note 1: based on f cy = f osc /2; doze mode and pll are disabled.
? 2008-2011 microchip technology inc. ds39927c-page 127 pic24f16ka102 family example 15-1: pwm period and duty cycle calculations ( 1 ) table 15-1: example pwm frequencies and resolutions at 4 mips (f cy = 4 mhz) ( 1 ) table 15-2: example pwm frequencies and resolutions at 16 mips (f cy = 16 mhz) ( 1 ) pwm frequency 7.6 hz 61 hz 122 hz 977 hz 3.9 khz 31.3 khz 125 khz timer prescaler ratio 8111111 period register value ffffh ffffh 7fffh 0fffh 03ffh 007fh 001fh resolution (bits) 16 16 15 12 10 7 5 note 1: based on f cy = f osc /2; doze mode and pll are disabled. pwm frequency 30.5 hz 244 hz 488 hz 3.9 khz 15.6 khz 125 khz 500 khz timer prescaler ratio 8111111 period register value ffffh ffffh 7fffh 0fffh 03ffh 007fh 001fh resolution (bits) 16 16 15 12 10 7 5 note 1: based on f cy = f osc /2; doze mode and pll are disabled. 1. find the timer period register value for a desired pwm frequency of 52.08 khz, where f osc = 8 mhz with pll (32 mhz device clock rate) and a timer2 prescaler setting of 1:1. t cy = 2 * t osc = 62.5 ns pwm period = 1/pwm frequency = 1/52.08 khz = 19.2 ? s pwm period = (pr2 + 1) ? t cy ? (timer 2 prescale value) 19.2 ? s = (pr2 + 1) ? 62.5 ns ? 1 pr2 = 306 2. find the maximum resolution of the duty cycle that can be used with a 52.08 khz frequency and a 32 mhz device clock rate: pwm resolution = log 10 (f cy /f pwm )/log 10 2) bits = (log 10 (16 mhz/52.08 khz)/log 10 2) bits = 8.3 bits note 1: based on t cy = 2 * t osc ; doze mode and pll are disabled.
pic24f16ka102 family ds39927c-page 128 ? 2008-2011 microchip technology inc. figure 15-1: output comp are module block diagram comparator output logic q s r ocm<2:0> output enable oc1 (1) set flag bit oc1if (1) oc1rs (1) mode select 3 note 1: where ?x? is depicted, reference is made to the registers associated with the respective output compare channel 1. 2: ocfa pin controls oc1 channel. 3: each output compare channel can use one of two selectable time bases. refer to the device data sheet for the time bases associated with the module. octsel 0 1 16 16 ocfa (2) tmr register inputs from time bases (3) period match signals from time bases (3) 0 1 oc1r (1)
? 2008-2011 microchip technology inc. ds39927c-page 129 pic24f16ka102 family 15.4 output compare register register 15-1: oc1con: output compare 1 control register u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ?ocsidl ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r-0, hc r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ocflt octsel ocm2 ocm1 ocm0 bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 ocsidl: stop output compare 1 in idle mode control bit 1 = output compare 1 will halt in cpu idle mode 0 = output compare 1 will continue to operate in cpu idle mode bit 12-5 unimplemented: read as ? 0 ? bit 4 ocflt: pwm fault condition status bit 1 = pwm fault condition has occurred (cleared in hw only) 0 = no pwm fault condition has occurred (this bit is only used when ocm<2:0> = 111 ) bit 3 octsel: output compare 1 timer select bit 1 = timer3 is the clock source for output compare 1 0 = timer2 is the clock source for output compare 1 refer to the device data sheet for specific time bases available to the output compare module. bit 2-0 ocm<2:0>: output compare 1 mode select bits 111 = pwm mode on oc1, fault pin; ocf1 enabled ( 1 ) 110 = pwm mode on oc1, fault pin; ocf1 disabled ( 1 ) 101 = initialize oc1 pin low, generate continuous output pulses on oc1 pin 100 = initialize oc1 pin low, generate single output pulse on oc1 pin 011 = compare event toggles oc1 pin 010 = initialize oc1 pin high, compare event forces oc1 pin low 001 = initialize oc1 pin low, compare event forces oc1 pin high 000 = output compare channel is disabled note 1: the ocfa pin controls the oc1 channel.
pic24f16ka102 family ds39927c-page 130 ? 2008-2011 microchip technology inc. register 15-2: padcfg1: pad co nfiguration control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? smbusdel ( 3 ) oc1tris ( 2 ) rtsecsel1 ( 1 , 4 ) rtsecsel0 ( 1 , 4 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-5 unimplemented: read as ? 0 ? bit 3 oc1tris: oc1 output tri-state select bit ( 2 ) 1 = oc1 output will not be active on the pin; ocpwm1 can still be used for internal triggers 0 = oc1 output will be active on the pin based on the ocpwm1 module settings bit 0 unimplemented: read as ? 0 ? note 1: to enable the actual rtcc output, the rtcoe (rcfgcal) bit needs to be set. 2: to enable the actual oc1 output, the ocpwm1 module has to be enabled. 3: bit 4 is described in section 17.0 ?inter-integrated circuit (i2c?)? . 4: bits 2 and 1 are described in section 19.0 real-time clock and calendar (rtcc) .
? 2008-2011 microchip technology inc. ds39927c-page 131 pic24f16ka102 family 16.0 serial peripheral interface (spi) the serial peripheral interface (spi) module is a synchronous serial interface useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial data eeproms, shift registers, display drivers, a/d converters, etc. the spi module is compatible with the spi and siop interfaces from motorola ? . the module supports operation in two buffer modes. in standard mode, data is shifted through a single serial buffer. in enhanced buffer mode, data is shifted through an 8-level fifo buffer. the module also supports a basic framed spi protocol while operating in either master or slave mode. a total of four framed spi configurations are supported. the spi serial interface consists of four pins: ? sdi1: serial data input ? sdo1: serial data output ? sck1: shift clock input or output ? ss1 : active-low slave select or frame synchronization i/o pulse the spi module can be configured to operate using 2, 3 or 4 pins. in the 3-pin mode, ss1 is not used. in the 2-pin mode, both sdo1 and ss1 are not used. block diagrams of the module in standard and enhanced buffer modes are displayed in figure 16-1 and figure 16-2 . the devices of the pic24f16ka102 family offer one spi module on a device. to set up the spi module for the standard master mode of operation: 1. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ipx bits in the ipc2 register to set the interrupt priority. 2. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 1 . 3. clear the spirov bit (spi1stat<6>). 4. enable spi operation by setting the spien bit (spi1stat<15>). 5. write the data to be transmitted to the spi1buf register. transmission (and reception) will start as soon as data is written to the spi1buf register. to set up the spi module for the standard slave mode of operation: 1. clear the spi1buf register. 2. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ip bits in the ipc2 register to set the interrupt priority. 3. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 0 . 4. clear the smp bit. 5. if the cke bit is set, then the ssen bit (spi1con1<7>) must be set to enable the ss1 pin. 6. clear the spirov bit (spi1stat<6>). 7. enable spi operation by setting the spien bit (spi1stat<15>). note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the serial peripheral interface, refer to the ?pic24f family reference manual? , section 23. ?serial peripheral interface (spi)? (ds39699). note: do not perform read-modify-write opera- tions (such as bit-oriented instructions) on the spi1buf register in either standard or enhanced buffer mode. note: in this section, the spi module is referred to as spi1, or separately as spi1. special function registers (sfrs) will follow a similar notation. for example, spi1con1 or spi1con2 refers to the control register for the spi1 module.
pic24f16ka102 family ds39927c-page 132 ? 2008-2011 microchip technology inc. figure 16-1: spi1 mo dule block diagram (standard buffer mode) internal data bus sdi1 sdo1 ss1 /fsync1 sck1 spi1sr bit 0 shift control edge select f cy primary 1:1/4/16/64 enable prescaler sync spi1buf control transfer transfer write spi1buf read spi1buf 16 spi1con1<1:0> spi1con1<4:2> master clock secondary prescaler 1:1 to 1:8 clock control
? 2008-2011 microchip technology inc. ds39927c-page 133 pic24f16ka102 family to set up the spi module for the enhanced buffer master (ebm) mode of operation: 1. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ipx bits in the ipc2 register. 2. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 1 . 3. clear the spirov bit (spi1stat<6>). 4. select enhanced buffer mode by setting the spiben bit (spi1con2<0>). 5. enable spi operation by setting the spien bit (spi1stat<15>). 6. write the data to be transmitted to the spi1buf register. transmission (and reception) will start as soon as data is written to the spi1buf register. to set up the spi module for the enhanced buffer slave mode of operation: 1. clear the spi1buf register. 2. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ipx bits in the ipc2 register to set the interrupt priority. 3. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 0 . 4. clear the smp bit. 5. if the cke bit is set, then the ssen bit must be set, thus enabling the ss1 pin. 6. clear the spirov bit (spi1stat<6>). 7. select enhanced buffer mode by setting the spiben bit (spi1con2<0>). 8. enable spi operation by setting the spien bit (spi1stat<15>). figure 16-2: spi1 mo dule block diagram (e nhanced buffer mode) internal data bus sdi1 sdo1 ss1 /fsync1 sck1 spi1sr bit 0 shift control edge select f cy enable sync spi1buf control transfer transfer write spi1buf read spi1buf 16 spi1con1<1:0> spi1con1<4:2> master clock clock control primary 1:1/4/16/64 prescaler secondary prescaler 1:1 to 1:8 8-level fifo receive buffer 8-level fifo transmit buffer
pic24f16ka102 family ds39927c-page 134 ? 2008-2011 microchip technology inc. register 16-1: spi1stat: spi1 status and control register r/w-0 u-0 r/w-0 u-0 u-0 r-0, hsc r-0, hsc r-0, hsc spien ? spisidl ? ? spibec2 spibec1 spibec0 bit 15 bit 8 r-0,hsc r/c-0, hs r/w-0, hsc r/w-0 r/w-0 r/w-0 r-0, hsc r-0, hsc srmpt spirov srxmpt sisel2 sisel1 sisel0 spitbf spirbf bit 7 bit 0 legend: u = unimplemented bit, read as ?0? hsc = hardware settable/clearable bit r = readable bit w = writable bit h = hardware settable bit c = clearable bit -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 spien: spi1 enable bit 1 = enables module and configures sck1, sdo1, sdi1 and ss1 as serial port pins 0 = disables module bit 14 unimplemented: read as ? 0 ? bit 13 spisidl: stop in idle mode bit 1 = discontinues module operation when device enters idle mode 0 = continues module operation in idle mode bit 12-11 unimplemented: read as ? 0 ? bit 10-8 spibec<2:0>: spi1 buffer element count bits (valid in enhanced buffer mode) master mode: number of spi transfers are pending. slave mode: number of spi transfers are unread. bit 7 srmpt: shift register (spi1sr) empty bit (valid in enhanced buffer mode) 1 = spi1 shift register is empty and ready to send or receive 0 = spi1 shift register is not empty bit 6 spirov: receive overflow flag bit 1 = a new byte/word is completely received and discarded the user software has not read the previous data in the spi1buf register. 0 = no overflow has occurred bit 5 srxmpt: receive fifo empty bit (valid in enhanced buffer mode) 1 = receive fifo is empty 0 = receive fifo is not empty bit 4-2 sisel<2:0>: spi1 buffer interrupt mode bits (valid in enhanced buffer mode) 111 = interrupt when the spi1 transmit buffer is full (spitbf bit is set) 110 = interrupt when the last bit is shifted into spi1sr; as a result, the tx fifo is empty 101 = interrupt when the last bit is shifted out of spi1sr; now the transmit is complete 100 = interrupt when one data byte is shifted into the spi1sr; as a result, the tx fifo has one open spot 011 = interrupt when the spi1 receive buffer is full (spirbf bit set) 010 = interrupt when the spi1 receive buffer is 3/4 or more full 001 = interrupt when data is available in receive buffer (srmpt bit is set) 000 = interrupt when the last data in the receive buffer is read; as a result, the buffer is empty (srxmpt bit is set)
? 2008-2011 microchip technology inc. ds39927c-page 135 pic24f16ka102 family bit 1 spitbf: spi1 transmit buffer full status bit 1 = transmit has not yet started, spi1txb is full 0 = transmit has started, spi1txb is empty in standard buffer mode: automatically set in hardware when the cpu writes to the spitbf location, loading spitbf. automatically cleared in hardware when the spi1 module transfers data from spi1txb to spirbf. in enhanced buffer mode: automatically set in hardware when cpu writes to the spi1buf location, loading the last available buffer location. automatically cleared in hardware when a buffer location is available for a cpu write. bit 0 spirbf: spi1 receive buffer full status bit 1 = receive is complete; spi1rxb is full 0 = receive is not complete; spi1rxb is empty in standard buffer mode: automatically set in hardware when spi1 transfers data from spirbf to spirbf. automatically cleared in hardware when the core reads the spi1buf location, reading spirbf. in enhanced buffer mode: automatically set in hardware when spi1 transfers data from spi1sr to buffer, filling the last unread buffer location. automatically cleared in hardware when a buffer location is available for a transfer from spi1sr. register 16-1: spi1stat: spi1 status and control register (continued)
pic24f16ka102 family ds39927c-page 136 ? 2008-2011 microchip technology inc. register 16-2: spi1con1: spi1 control register 1 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? dissck dissdo mode16 smp cke ( 1 ) bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ssen ckp msten spre2 spre1 spre0 ppre1 ppre0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12 dissck: disable sck1 pin bit (spi master modes only) 1 = internal spi clock is disabled, pin functions as i/o 0 = internal spi clock is enabled bit 11 dissdo: disables sdo1 pin bit 1 = sdo1 pin is not used by module; pin functions as i/o 0 = sdo1 pin is controlled by the module bit 10 mode16: word/byte communication select bit 1 = communication is word-wide (16 bits) 0 = communication is byte-wide (8 bits) bit 9 smp: spi1 data input sample phase bit master mode: 1 = input data is sampled at the end of data output time 0 = input data is sampled at the middle of data output time slave mode: smp must be cleared when spi1 is used in slave mode. bit 8 cke: spi1 clock edge select bit ( 1 ) 1 = serial output data changes on transition from active clock state to idle clock state (see bit 6) 0 = serial output data changes on transition from idle clock state to active clock state (see bit 6) bit 7 ssen: slave select enable bit (slave mode) 1 =ss1 pin is used for slave mode 0 =ss1 pin is not used by the module; pin is controlled by port function bit 6 ckp: clock polarity select bit 1 = idle state for clock is a high level; active state is a low level 0 = idle state for clock is a low level; active state is a high level bit 5 msten: master mode enable bit 1 = master mode 0 =slave mode bit 4-2 spre<2:0>: secondary prescale bits (master mode) 111 = secondary prescale 1:1 110 = secondary prescale 2:1 . . . 000 = secondary prescale 8:1 note 1: the cke bit is not used in the framed spi modes. the user should program this bit to ? 0 ? for the framed spi modes (frmen = 1 ).
? 2008-2011 microchip technology inc. ds39927c-page 137 pic24f16ka102 family bit 1-0 ppre<1:0>: primary prescale bits (master mode) 11 = primary prescale 1:1 10 = primary prescale 4:1 01 = primary prescale 16:1 00 = primary prescale 64:1 register 16-2: spi1con1: spi1 control register 1 (continued) note 1: the cke bit is not used in the framed spi modes. the user should program this bit to ? 0 ? for the framed spi modes (frmen = 1 ). register 16-3: spi1con2: spi1 control register 2 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 u-0 frmen spifsd spifpol ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? spife spiben bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 frmen: framed spi1 support bit 1 = framed spi1 support is enabled 0 = framed spi1 support is disabled bit 14 spifsd: frame sync pulse direction control on ss1 pin bit 1 = frame sync pulse input (slave) 0 = frame sync pulse output (master) bit 13 spifpol: frame sync pulse polarity bit (frame mode only) 1 = frame sync pulse is active-high 0 = frame sync pulse is active-low bit 12-2 unimplemented: read as ? 0 ? bit 1 spife: frame sync pulse edge select bit 1 = frame sync pulse coincides with the first bit clock 0 = frame sync pulse precedes the first bit clock bit 0 spiben: enhanced buffer enable bit 1 = enhanced buffer is enabled 0 = enhanced buffer is disabled (legacy mode)
pic24f16ka102 family ds39927c-page 138 ? 2008-2011 microchip technology inc. equation 16-1: relationship between device and spi clock speed (1) table 16-1: sample sck frequencies ( 1 , 2 ) f cy = 16 mhz secondary prescaler settings 1:12:14:16:18:1 primary prescaler settings 1:1 invalid 8000 4000 2667 2000 4:1 4000 2000 1000 667 500 16:1 1000 500 250 167 125 64:1 250 125 63 42 31 f cy = 5 mhz primary prescaler settings 1:1 5000 2500 1250 833 625 4:1 1250 625 313 208 156 16:1 313 156 78 52 39 64:17839201310 note 1: based on f cy = f osc /2; doze mode and pll are disabled. 2: sck1 frequencies are indicated in khz. primary prescaler * secondary prescaler f cy f sck = note 1: based on f cy = f osc /2; doze mode and pll are disabled.
? 2008-2011 microchip technology inc. ds39927c-page 139 pic24f16ka102 family 17.0 inter-integrated circuit (i 2 c?) the inter-integrated circuit (i 2 c) module is a serial interface useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial data eeproms, display drivers, a/d converters, etc. the i 2 c module supports these features: ? independent master and slave logic ? 7-bit and 10-bit device addresses ? general call address, as defined in the i 2 c protocol ? automatic clock stretching to provide delays for the processor to respond to a slave data request ? both 100 khz and 400 khz bus specifications ? configurable address masking ? multi-master modes to prevent loss of messages in arbitration ? bus repeater mode, allowing the acceptance of all messages as a slave regardless of the address ? automatic scl figure 17-1 illustrates a block diagram of the module. 17.1 pin remapping options the i 2 c module is tied to a fixed pin. to allow flexibility with peripheral multiplexing, the i2c1 module in 28-pin devices can be reassigned to the alternate pins, designated as scl1 and sda1 during device configuration. pin assignment is controlled by the i2c1sel configuration bit. programming this bit (= 0 ) multiplexes the module to the scl1 and sda1 pins. 17.2 communicating as a master in a single master environment the details of sending a message in master mode depends on the communications protocol for the device being communicated with. typically, the sequence of events is as follows: 1. assert a start condition on sda1 and scl1. 2. send the i 2 c device address byte to the slave with a write indication. 3. wait for and verify an acknowledge from the slave. 4. send the first data byte (sometimes known as the command) to the slave. 5. wait for and verify an acknowledge from the slave. 6. send the serial memory address low byte to the slave. 7. repeat steps 4 and 5 until all data bytes are sent. 8. assert a repeated start condition on sda1 and scl1. 9. send the device address byte to the slave with a read indication. 10. wait for and verify an acknowledge from the slave. 11. enable master reception to receive serial memory data. 12. generate an ack or nack condition at the end of a received byte of data. 13. generate a stop condition on sda1 and scl1. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the inter-integrated circuit, refer to the ?pic24f family reference manual? , section 24. ?inter-integrated circuit? (i 2 c?)? (ds39702).
pic24f16ka102 family ds39927c-page 140 ? 2008-2011 microchip technology inc. figure 17-1: i 2 c? block diagram i2c1rcv internal data bus scl1 sda1 shift match detect i2c1add start and stop bit detect clock address match clock stretching i2c1trn lsb shift clock brg down counter reload control t cy /2 start and stop bit generation acknowledge generation collision detect i2c1con i2c1stat control logic read lsb write read i2c1brg write read write read write read write read write read i2c1msk i2c1rsr
? 2008-2011 microchip technology inc. ds39927c-page 141 pic24f16ka102 family 17.3 setting baud rate when operating as a bus master to compute the baud rate generator (brg) reload value, use equation 17-1 . equation 17-1: computing baud rate reload value (1) 17.4 slave address masking the i2c1msk register ( register 17-3 ) designates address bit positions as ?don?t care? for both 7-bit and 10-bit addressing modes. setting a particular bit location (= 1 ) in the i2c1msk register causes the slave module to respond whether the corresponding address bit value is ? 0 ? or ? 1 ?. for example, when i2c1msk is set to ? 00100000 ?, the slave module will detect both addresses: ? 0000000 ? and ? 00100000 ?. to enable address masking, the intelligent peripheral management interface (ipmi) must be disabled by clearing the ipmien bit (i2c1con<11>). table 17-1: i 2 c? clock rates ( 1 ) table 17-2: i 2 c? reserved addresses ( 1 ) i2c1brg f cy f scl ----------- - f cy 10 000 000 ?? ----------------------------- - ? ?? ?? 1 ? = f scl f cy i2c1brg 1 f cy 10 000 000 ?? ----------------------------- - ++ --------------------------------------------------------------------- - = or note 1: based on f cy = f osc /2; doze mode and pll are disabled. note: as a result of changes in the i 2 c protocol, the addresses in tab l e 1 7- 2 are reserved and will not be acknowledged in slave mode. this includes any address mask settings that include any of these addresses. required system f scl f cy i2c1brg value actual f scl (decimal) (hexadecimal) 100 khz 16 mhz 157 9d 100 khz 100 khz 8 mhz 78 4e 100 khz 100 khz 4 mhz 39 27 99 khz 400 khz 16 mhz 37 25 404 khz 400 khz 8 mhz 18 12 404 khz 400khz 4mhz 9 9 385khz 400khz 2mhz 4 4 385khz 1 mhz 16 mhz 13 d 1.026 mhz 1mhz 8mhz 6 6 1.026mhz 1mhz 4mhz 3 3 0.909mhz note 1: based on f cy = f osc /2; doze mode and pll are disabled; slave address r/w bit description 0000 000 0 general call address ( 2 ) 0000 000 1 start byte 0000 001 x cbus address 0000 010 x reserved 0000 011 x reserved 0000 1xx x hs mode master code 1111 1xx x reserved 1111 0xx x 10-bit slave upper byte ( 3 ) note 1: the address bits listed here will never cause an address match, independent of the address mask settings. 2: the address will be acknowledged only if gcen = 1 . 3: a match on this address can only occur on the upper byte in 10-bit addressing mode.
pic24f16ka102 family ds39927c-page 142 ? 2008-2011 microchip technology inc. register 17-1: i2c1con: i2c1 control register r/w-0 u-0 r/w-0 r/w-1 hc r/w-0 r/w-0 r/w-0 r/w-0 i2cen ? i2csidl sclrel ipmien a10m disslw smen bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0, hc r/w-0, hc r/w-0, hc r/w-0, hc r/w-0, hc gcen stren ackdt acken rcen pen rsen sen bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 i2cen: i2c1 enable bit 1 = enables the i2c1 module and configures the sda1 and scl1 pins as serial port pins 0 = disables the i2c1 module; all i 2 c? pins are controlled by port functions bit 14 unimplemented: read as ? 0 ? bit 13 i2csidl: stop in idle mode bit 1 = discontinues module operation when device enters an idle mode 0 = continues module operation in idle mode bit 12 sclrel: scl1 release control bit (when operating as i 2 c slave) 1 = releases scl1 clock 0 = holds scl1 clock low (clock stretch) if stren = 1 : bit is r/w (i.e., software may write ? 0 ? to initiate stretch and write ? 1 ? to release clock). hardware is clear at the beginning of slave transmission; hardware is clear at the end of slave reception. if stren = 0 : bit is r/s (i.e., software may only write ? 1 ? to release clock). hardware is clear at the beginning of slave transmission. bit 11 ipmien: intelligent peripheral management interface (ipmi) enable bit 1 = ipmi support mode is enabled; all addresses are acknowledged 0 = ipmi support mode is disabled bit 10 a10m: 10-bit slave addressing bit 1 = i2c1add is a 10-bit slave address 0 = i2c1add is a 7-bit slave address bit 9 disslw: disable slew rate control bit 1 = slew rate control is disabled 0 = slew rate control is enabled bit 8 smen: smbus input levels bit 1 = enables i/o pin thresholds compliant with the smbus specification 0 = disables the smbus input thresholds bit 7 gcen: general call enable bit (when operating as i 2 c slave) 1 = enables interrupt when a general call address is received in the i2c1rsr (module is enabled for reception) 0 = general call address is disabled bit 6 stren: scl1 clock stretch enable bit (when operating as i 2 c slave) used in conjunction with the sclrel bit. 1 = enables software or receive clock stretching 0 = disables software or receive clock stretching
? 2008-2011 microchip technology inc. ds39927c-page 143 pic24f16ka102 family bit 5 ackdt: acknowledge data bit (when operating as i 2 c master; applicable during master receive) value that will be transmitted when the software initiates an acknowledge sequence. 1 = sends nack during acknowledge 0 = sends ack during acknowledge bit 4 acken: acknowledge sequence enable bit (when operating as i 2 c master; applicable during master receive) 1 = initiates acknowledge sequence on sda1 and scl1 pins and transmits ackdt data bit; hardware is clear at the end of the master acknowledge sequence 0 = acknowledge sequence is not in progress bit 3 rcen: receive enable bit (when operating as i 2 c master) 1 = enables receive mode for i 2 c; hardware is clear at the end of eighth bit of master receive data byte 0 = receive sequence not in progress bit 2 pen: stop condition enable bit (when operating as i 2 c master) 1 = initiates stop condition on sda1 and scl1 pins; hardware is clear at end of master stop sequence 0 = stop condition is not in progress bit 1 rsen: repeated start condition enable bit (when operating as i 2 c master) 1 = initiates repeated start condition on sda1 and scl1 pins; hardware is clear at end of master repeated start sequence 0 = repeated start condition is not in progress bit 0 sen: start condition enable bit (when operating as i 2 c master) 1 = initiates start condition on sda1 and scl1 pins; hardware is clear at end of master start sequence 0 = start condition is not in progress register 17-1: i2c1con: i2c1 control register (continued)
pic24f16ka102 family ds39927c-page 144 ? 2008-2011 microchip technology inc. register 17-2: i2c1stat: i2c1 status register r-0, hsc r-0, hsc u-0 u-0 u-0 r/c-0, hs r-0, hsc r-0, hsc ackstat trstat ? ? ? bcl gcstat add10 bit 15 bit 8 r/c-0, hs r/c-0, hs r-0, hsc r/c-0, hsc r/c-0, hsc r-0, hsc r-0, hsc r-0, hsc iwcol i2cov d/a psr/w rbf tbf bit 7 bit 0 legend: c = clearable bit hs = hardware settable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ackstat: acknowledge status bit 1 = nack was detected last 0 = ack was detected last hardware is set or clear at of acknowledge. bit 14 trstat: transmit status bit (when operating as i 2 c? master; applicable to master transmit operation.) 1 = master transmit is in progress (8 bits + ack) 0 = master transmit is not in progress hardware is set at beginning of master transmissi on; hardware is clear at end of slave acknowledge. bit 13-11 unimplemented: read as ? 0 ? bit 10 bcl: master bus collision detect bit 1 = a bus collision has been detected during a master operation 0 = no collision hardware is set at detection of bus collision. bit 9 gcstat: general call status bit 1 = general call address was received 0 = general call address was not received hardware is set when address matches general call address; hardware is clear at stop detection. bit 8 add10: 10-bit address status bit 1 = 10-bit address was matched 0 = 10-bit address was not matched hardware is set at match of 2 nd byte of matched 10-bit address; hardware is clear at stop detection. bit 7 iwcol: write collision detect bit 1 = an attempt to write to the i2c1trn register failed because the i 2 c module is busy 0 = no collision hardware is set at occurrence of write to i2c1trn while busy (cleared by software). bit 6 i2cov: receive overflow flag bit 1 = a byte was received while the i2c1rcv register is still holding the previous byte 0 = no overflow hardware is set at attempt to transfer to i2c1rcv (cleared by software). bit 5 d/a : data/address bit (when operating as i 2 c slave) 1 = indicates that the last byte received was data 0 = indicates that the last byte received was the device address hardware is clear at device address match; hardware is set by a write to i2c1trn or by reception of slave byte. bit 4 p: stop bit 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last hardware is set or clear when start, repeated start or stop is detected.
? 2008-2011 microchip technology inc. ds39927c-page 145 pic24f16ka102 family bit 3 s: start bit 1 = indicates that a start (or repeated start) bit has been detected last 0 = start bit was not detected last hardware is set or clear when start, repeated start or stop is detected. bit 2 r/w : read/write information bit (when operating as i 2 c slave) 1 = read ? indicates the data transfer is output from slave 0 = write ? indicates the data transfer is input to slave hardware is set or clear after reception of i 2 c device address byte. bit 1 rbf: receive buffer full status bit 1 = receive complete, i2c1rcv is full 0 = receive not complete, i2c1rcv is empty hardware is set when i2c1rcv is written with received byte; hardware is clear when software reads i2c1rcv. bit 0 tbf: transmit buffer full status bit 1 = transmit in progress, i2c1trn is full 0 = transmit complete, i2c1trn is empty hardware is set when software writes to i2c1trn; hardware is clear at completion of data transmission. register 17-2: i2c1stat: i2c1 status register (continued)
pic24f16ka102 family ds39927c-page 146 ? 2008-2011 microchip technology inc. register 17-3: i2c1msk: i2c1 sl ave mode address mask register u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? amsk9 amsk8 bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 amsk7 amsk6 amsk5 amsk4 amsk3 amsk2 amsk1 amsk0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-10 unimplemented: read as ? 0 ? bit 9-0 amsk<9:0>: mask for address bit x select bits 1 = enable masking for bit x of incoming message address; bit match is not required in this position 0 = disable masking for bit x; bit match is required in this position register 17-4: padcfg1: pad co nfiguration control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 ? ? ? smbusdel oc1tris ( 2 , 3 ) rtsecsel1 ( 1 , 3 ) rtsecsel0 ( 1 , 3 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-5 unimplemented: read as ? 0 ? bit 4 smbusdel: smbus sda input delay select bit 1 = the i 2 c module is configured for a longer smbus input delay (nominal 300 ns delay) 0 = the 1 2 c module is configured for a legacy input delay (nominal 150 ns delay) bit 0 unimplemented: read as ? 0 ? note 1: to enable the actual rtcc output, the rtcoe (rcfgcal<10>) bit needs to be set. 2: to enable the actual oc1 output, the ocpwm1 module has to be enabled. 3: bits<3:1> are described in related chapters.
? 2008-2011 microchip technology inc. ds39927c-page 147 pic24f16ka102 family 18.0 universal asynchronous receiver transmitter (uart) the universal asynchronous receiver transmitter (uart) module is one of the serial i/o modules avail- able in this pic24f device family. the uart is a full-duplex asynchronous system that can communicate with peripheral devices, such as personal computers, lin, rs-232 and rs-485 interfaces. this module also supports a hardware flow control option with the uxcts and uxrts pins, and also includes an irda ? encoder and decoder. the primary features of the uart module are: ? full-duplex, 8-bit or 9-bit data transmission through the uxtx and uxrx pins ? even, odd or no parity options (for 8-bit data) ? one or two stop bits ? hardware flow control option with uxcts and uxrts pins ? fully integrated baud rate generator (ibrg) with 16-bit prescaler ? baud rates ranging from 1 mbps to 15 bps at 16 mips ? 4-deep, first-in-first-out (fifo) transmit data buffer ? 4-deep fifo receive data buffer ? parity, framing and buffer overrun error detection ? support for 9-bit mode with address detect (9 th bit = 1 ) ? transmit and receive interrupts ? loopback mode for diagnostic support ? support for sync and break characters ? supports automatic baud rate detection ? irda encoder and decoder logic ? 16x baud clock output for irda support a simplified block diagram of the uart is displayed in figure 18-1 . the uart module consists of these important hardware elements: ? baud rate generator ? asynchronous transmitter ? asynchronous receiver figure 18-1: uart simplified block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the universal asynchronous receiver transmitter, refer to the ?pic24f family reference manual? , section 21. ?uart? (ds39708). uxrx irda ? hardware flow control uartx receiver uartx transmitter uxtx uxcts uxrts uxbclk baud rate generator
pic24f16ka102 family ds39927c-page 148 ? 2008-2011 microchip technology inc. 18.1 uart baud rate generator (brg) the uart module includes a dedicated 16-bit baud rate generator (brg). the uxbrg register controls the period of a free-running, 16-bit timer. equation 18-1 provides the formula for computation of the baud rate with brgh = 0 . equation 18-1: uart baud rate with brgh = 0 ( 1 ) example 18-1 provides the calculation of the baud rate error for the following conditions: ?f cy = 4 mhz ? desired baud rate = 9600 the maximum baud rate (brgh = 0 ) possible is f cy /16 (for uxbrg = 0 ) and the minimum baud rate possible is f cy /(16 * 65536). equation 18-2 provides the formula for computation of the baud rate with brgh = 1 . equation 18-2: uart baud rate with brgh = 1 ( 1 ) the maximum baud rate (brgh = 1 ) possible is f cy /4 (for uxbrg = 0 ) and the minimum baud rate possible is f cy /(4 * 65536). writing a new value to the uxbrg register causes the brg timer to be reset (cleared). this ensures the brg does not wait for a timer overflow before generating the new baud rate. example 18-1: baud rate erro r calculation (brgh = 0 ) ( 1 ) note 1: based on f cy = f osc /2; doze mode and pll are disabled. baud rate = f cy 16 ? (uxbrg + 1) f cy 16 ? baud rate uxbrg = ? 1 baud rate = f cy 4 ? (uxbrg + 1) f cy 4 ? baud rate uxbrg = ? 1 note 1: based on f cy = f osc /2; doze mode and pll are disabled. desired baud rate = f cy /(16 (uxbrg + 1)) solving for uxbrg value: uxbrg = ((f cy /desired baud rate)/16) ? 1 uxbrg = ((4000000/9600)/16) ? 1 uxbrg = 25 calculated baud rate = 4000000/(16 (25 + 1)) = 9615 error = (calculated baud rate ? desired baud rate) desired baud rate = (9615 ? 9600)/9600 =0.16% note 1: based on f cy = f osc /2; doze mode and pll are disabled.
? 2008-2011 microchip technology inc. ds39927c-page 149 pic24f16ka102 family 18.2 transmitting in 8-bit data mode 1. set up the uart: a) write appropriate values for data, parity and stop bits. b) write appropriate baud rate value to the uxbrg register. c) set up transmit and receive interrupt enable and priority bits. 2. enable the uart. 3. set the utxen bit (causes a transmit interrupt two cycles after being set). 4. write data byte to lower byte of uxtxreg word. the value will be immediately transferred to the transmit shift register (tsr) and the serial bit stream will start shifting out with the next rising edge of the baud clock. 5. alternately, the data byte may be transferred while utxen = 0 , and then, the user may set utxen. this will cause the serial bit stream to begin immediately because the baud clock will start from a cleared state. 6. a transmit interrupt will be generated as per interrupt control bit, utxiselx. 18.3 transmitting in 9-bit data mode 1. set up the uart (as described in section 18.2 ?transmitting in 8-bit data mode? ). 2. enable the uart. 3. set the utxen bit (causes a transmit interrupt two cycles after being set). 4. write uxtxreg as a 16-bit value only. 5. a word write to uxtxreg triggers the transfer of the 9-bit data to the tsr. the serial bit stream will start shifting out with the first rising edge of the baud clock. 6. a transmit interrupt will be generated as per the setting of control bit, utxiselx. 18.4 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. 1. configure the uart for the desired mode. 2. set utxen and utxbrk ? sets up the break character. 3. load the uxtxreg with a dummy character to initiate transmission (value is ignored). 4. write ?55h? to uxtxreg ? loads the sync character into the transmit fifo. 5. after the break has been sent, the utxbrk bit is reset by hardware. the sync character now transmits. 18.5 receiving in 8-bit or 9-bit data mode 1. set up the uart (as described in section 18.2 ?transmitting in 8-bit data mode? ). 2. enable the uart. 3. a receive interrupt will be generated when one or more data characters have been received, as per interrupt control bit, urxiselx. 4. read the oerr bit to determine if an overrun error has occurred. the oerr bit must be reset in software. 5. read uxrxreg. the act of reading the uxrxreg character will move the next character to the top of the receive fifo, including a new set of perr and ferr values. 18.6 operation of uxcts and uxrts control pins uartx clear to send (uxcts ) and request to send (uxrts ) are the two hardware-controlled pins that are associated with the uart module. these two pins allow the uart to operate in simplex and flow control modes. they are implemented to control the transmission and reception between the data terminal equipment (dte). the uen<1:0> bits in the uxmode register configure these pins. 18.7 infrared support the uart module provides two types of infrared uart support: one is the irda clock output to support an external irda encoder and decoder device (legacy module support), and the other is the full implementation of the irda encoder and decoder. as the irda modes require a 16x baud clock, they will only work when the brgh bit (uxmode<3>) is ? 0 ?. 18.7.1 external irda support ? irda clock output to support external irda encoder and decoder devices, the uxbclk pin (same as the uxrts pin) can be configured to generate the 16x baud clock. when uen<1:0> = 11 , the uxbclk pin will output the 16x baud clock if the uart module is enabled; it can be used to support the irda codec chip. 18.7.2 built-in irda encoder and decoder the uart has full implementation of the irda encoder and decoder as part of the uart module. the built-in irda encoder and decoder functionality is enabled using the iren bit (uxmode<12>). when enabled (iren = 1 ), the receive pin (uxrx) acts as the input from the infrared receiver. the transmit pin (uxtx) acts as the output to the infrared transmitter.
pic24f16ka102 family ds39927c-page 150 ? 2008-2011 microchip technology inc. register 18-1: uxmode: uartx mode register r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 ( 2 ) r/w-0 ( 2 ) uarten ? usidl iren ( 1 ) rtsmd ? uen1 uen0 bit 15 bit 8 r/c-0, hc r/w-0 r/w-0, hc r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel bit 7 bit 0 legend: c = clearable bit hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 uarten: uartx enable bit 1 = uartx is enabled; all uartx pins are controlled by uartx as defined by uen<1:0> 0 = uartx is disabled; all uartx pins are controlled by port latches; uartx power consumption is minimal bit 14 unimplemented: read as ? 0 ? bit 13 usidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12 iren: irda ? encoder and decoder enable bit ( 1 ) 1 = irda encoder and decoder are enabled 0 = irda encoder and decoder are disabled bit 11 rtsmd: mode selection for uxrts pin bit 1 =uxrts pin is in simplex mode 0 =uxrts pin is in flow control mode bit 10 unimplemented: read as ? 0 ? bit 9-8 uen<1:0>: uartx enable bits ( 2 ) 11 = uxtx, uxrx and uxbclk pins are enabled and used; uxcts pin is controlled by port latches 10 = uxtx, uxrx, uxcts and uxrts pins are enabled and used 01 = uxtx, uxrx and uxrts pins are enabled and used; uxcts pin is controlled by port latches 00 = uxtx and uxrx pins are enabled and used; uxcts and uxrts /uxbclk pins are controlled by port latches bit 7 wake: wake-up on start bit detect during sleep mode enable bit 1 = uartx will continue to sample the uxrx pin; interrupt generated on falling edge, bit is cleared in hardware on the following rising edge 0 = no wake-up is enabled bit 6 lpback: uartx loopback mode select bit 1 = enable loopback mode 0 = loopback mode is disabled bit 5 abaud: auto-baud enable bit 1 = enable baud rate measurement on the next character ? requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement is disabled or completed bit 4 rxinv: receive polarity inversion bit 1 = uxrx idle state is ? 0 ? 0 = uxrx idle state is ? 1 ? note 1: this feature is only available for the 16x brg mode (brgh = 0 ). 2: bit availability depends on pin availability.
? 2008-2011 microchip technology inc. ds39927c-page 151 pic24f16ka102 family bit 3 brgh: high baud rate enable bit 1 = brg generates 4 clocks per bit period (4x baud clock, high-speed mode) 0 = brg generates 16 clocks per bit period (16x baud clock, standard mode) bit 2-1 pdsel<1:0>: parity and data selection bits 11 = 9-bit data, no parity 10 = 8-bit data, odd parity 01 = 8-bit data, even parity 00 = 8-bit data, no parity bit 0 stsel: stop bit selection bit 1 = two stop bits 0 = one stop bit register 18-1: uxmode: uartx mode register (continued) note 1: this feature is only available for the 16x brg mode (brgh = 0 ). 2: bit availability depends on pin availability.
pic24f16ka102 family ds39927c-page 152 ? 2008-2011 microchip technology inc. register 18-2: uxsta: uartx status and control register r/w-0 r/w-0 r/w-0 u-0 r/w-0, hc r/w-0 r-0, hsc r-1, hsc utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt bit 15 bit 8 r/w-0 r/w-0 r/w-0 r-1, hsc r-0, hsc r-0, hsc r/c-0, hs r-0, hsc urxisel1 urxisel0 adden ridle perr ferr oerr urxda bit 7 bit 0 legend: hc = hardware clearable bit c = clearable bit hs = hardware settable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15,13 utxisel<1:0>: transmission interrupt mode selection bits 11 = reserved; do not use 10 = interrupt when a character is transferred to the transmit shift register (tsr), and as a result, the transmit buffer becomes empty 01 = interrupt when the last character is shifted out of the transmit shift register; all transmit operations are completed 00 = interrupt when a character is transferred to the transmit shift register (this implies there is at least one character open in the transmit buffer) bit 14 utxinv: irda ? encoder transmit polarity inversion bit if iren = 0 : 1 = uxtx idle ? 0 ? 0 = uxtx idle ? 1 ? if iren = 1 : 1 = uxtx idle ? 1 ? 0 = uxtx idle ? 0 ? bit 12 unimplemented: read as ? 0 ? bit 11 utxbrk: transmit break bit 1 = send sync break on next transmission ? start bit, followed by twelve ? 0 ? bits, followed by stop bit; cleared by hardware upon completion 0 = sync break transmission is disabled or completed bit 10 utxen: transmit enable bit 1 = transmit is enabled, uxtx pin is controlled by uartx 0 = transmit is disabled, any pending transmission is aborted and buffer is reset. uxtx pin is controlled by the port register. bit 9 utxbf: transmit buffer full status bit (read-only) 1 = transmit buffer is full 0 = transmit buffer is not full, at least one more character can be written bit 8 trmt: transmit shift register empty bit (read-only) 1 = transmit shift register is empty and transmit buffer is empty (the last transmission has completed) 0 = transmit shift register is not empty, a transmission is in progress or queued bit 7-6 urxisel<1:0>: receive interrupt mode selection bits 11 = interrupt is set on rsr transfer, making the receive buffer full (i.e., has 4 data characters) 10 = interrupt is set on rsr transfer, making the receive buffer 3/4 full (i.e., has 3 data characters) 0x = interrupt is set when any character is received and transferred from the rsr to the receive buffer; receive buffer has one or more characters
? 2008-2011 microchip technology inc. ds39927c-page 153 pic24f16ka102 family bit 5 adden: address character detect bit (bit 8 of received data = 1 ) 1 = address detect mode is enabled. if 9-bit mode is not selected, this does not take effect. 0 = address detect mode is disabled bit 4 ridle: receiver idle bit (read-only) 1 = receiver is idle 0 = receiver is active bit 3 perr: parity error status bit (read-only) 1 = parity error has been detected for the current character (character at the top of the receive fifo) 0 = parity error has not been detected bit 2 ferr: framing error status bit (read-only) 1 = framing error has been detected for the current character (character at the top of the receive fifo) 0 = framing error has not been detected bit 1 oerr: receive buffer overrun error status bit (clear/read-only) 1 = receive buffer has overflowed 0 = receive buffer has not overflowed (clearing a previously set oerr bit ( 1 ? 0 transition) will reset the receiver buffer and the rsr to the empty state) bit 0 urxda: receive buffer data available bit (read-only) 1 = receive buffer has data; at least one more character can be read 0 = receive buffer is empty register 18-2: uxsta: uartx status and control register (continued)
pic24f16ka102 family ds39927c-page 154 ? 2008-2011 microchip technology inc. register 18-3: uxtxreg: uartx transmit register u-x u-x u-x u-x u-x u-x u-x w-x ? ? ? ? ? ? ?utx8 bit 15 bit 8 w-x w-x w-x w-x w-x w-x w-x w-x utx7 utx6 utx5 utx4 utx3 utx2 utx1 utx0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 utx8: data of the transmitted character bit (in 9-bit mode) bit 7-0 utx<7:0>: data of the transmitted character bits register 18-4: uxrxreg: uartx receive register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc ? ? ? ? ? ? ?urx8 bit 15 bit 8 r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc urx7 urx6 urx5 urx4 urx3 urx2 urx1 urx0 bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 urx8: data of the received character bit (in 9-bit mode) bit 7-0 urx<7:0>: data of the received character bits
? 2008-2011 microchip technology inc. ds39927c-page 155 pic24f16ka102 family 19.0 real-time clock and calendar (rtcc) the rtcc provides the user with a real-time clock and calendar (rtcc) function that can be calibrated. key features of the rtcc module are: ? operates in deep sleep mode ? selectable clock source ? provides hours, minutes and seconds using 24-hour format ? visibility of one half second period ? provides calendar ? weekday, date, month and year ? alarm-configurable for half a second, one second, 10 seconds, one minute, 10 minutes, one hour, one day, one week, one month or one year ? alarm repeat with decrementing counter ? alarm with indefinite repeat chime ? year 2000 to 2099 leap year correction ? bcd format for smaller software overhead ? optimized for long-term battery operation ? user calibration of the 32.768 khz clock crystal/32k intrc frequency with periodic auto-adjust 19.1 rtcc source clock the user can select between the sosc crystal oscillator or the lprc internal oscillator as the clock reference for the rtcc module. this is configured using the rtcosc (fds<5>) configuration bit. this gives the user an option to trade off system cost, accuracy and power consumption, based on the overall system needs. the rtcc will continue to run, along with its chosen clock source, while the device is held in reset with mclr and will continue running after mclr is released. figure 19-1: rt cc block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the real-time clock and calendar, refer to the ?pic24f family reference manual? , section 29. ?real-time clock and calendar (rtcc)? (ds39696). rtcc clock domain cpu clock domain rtcc rtcc prescalers rtcc timer comparator alarm registers with masks repeat counter 0.5 sec rtcc interrupt logic alrmval rtcval alcfgrpt rcfgcal alarm event year mthdy wkdyhr minsec almthdy alwdhr alminsec rtcc interrupt rtsecsel<1:0> rtcoe 10 00 01 clock source 1s pin alarm pulse input from sosc/lprc oscillator
pic24f16ka102 family ds39927c-page 156 ? 2008-2011 microchip technology inc. 19.2 rtcc module registers the rtcc module registers are organized into three categories: ? rtcc control registers ? rtcc value registers ? alarm value registers 19.2.1 register mapping to limit the register interface, the rtcc timer and alarm time registers are accessed through corresponding register pointers. the rtcc value register window (rtcvalh and rtcvall) uses the rtcptr bits (rcfgcal<9:8>) to select the desired timer register pair (see table 19-1 ). by writing the rtcvalh byte, the rtcc pointer value, the rtcptr<1:0> bits decrement by one until they reach ? 00 ?. once they reach ? 00 ?, the minutes and seconds value will be accessible through rtcvalh and rtcvall until the pointer value is manually changed. table 19-1: rtcval register mapping the alarm value register window (alrmvalh and alrmvall) uses the alrmptr bits (alcfgrpt<9:8>) to select the desired alarm register pair (see table 19-2 ). by writing the alrmvalh byte, the alarm pointer value bits (alrmptr<1:0>) decrement by one until they reach ? 00 ?. once they reach ? 00 ?, the alrmmin and alrmsec value will be accessible through alrmvalh and alrmvall until the pointer value is manually changed. table 19-2: alrmval register mapping considering that the 16-bit core does not distinguish between 8-bit and 16-bit read operations, the user must be aware that when reading either the alrmvalh or alrmvall bytes, the alrmptr<1:0> value will be decremented. the same applies to the rtcvalh or rtcvall bytes with the rtcptr<1:0> being decremented. 19.2.2 write lock in order to perform a write to any of the rtcc timer registers, the rtcwren bit (rcfgcal<13>) must be set (refer to example 19-1 ). 19.2.3 selecting rtcc clock source the clock source for the rtcc module can be selected using the rtcosc (fds<5>) bit. when the bit is set to ? 1 ?, the secondary oscillator (sosc) is used as the ref- erence clock and when the bit is ? 0 ?, lprc is used as the reference clock. example 19-1: setting the rtcwren bit rtcptr<1:0> rtcc value register window rtcval<15:8> rtcval<7:0> 00 minutes seconds 01 weekday hours 10 month day 11 ? year alrmptr <1:0> alarm value register window alrmval<15:8> alrmval<7:0> 00 alrmmin alrmsec 01 alrmwd alrmhr 10 alrmmnth alrmday 11 ?? note: this only applies to read operations and not write operations. note: to avoid accidental writes to the timer, it is recommended that the rtcwren bit (rcfgcal<13>) is kept clear at any other time. for the rtcwren bit to be set, there is only one instruction cycle time window allowed between the 55h/aa sequence and the setting of rtcwren; therefore, it is recommended that code follow the procedure in example 19-1 . asm volatile ("push w7") ; asm volatile ("push w8 " ) ; asm volatile ("disi #5 " ) ; asm volatile ("mov #0x55, w7 " ) ; asm volatile ("mov w7, _nvmkey " ); asm volatile ("mov #0xaa, w8 " ); asm volatile ("mov w8, _nvmkey " ); asm volatile ("bset _rcfgcal, #13 " ) ; //set the rtcwren bit asm volatile ("pop w8 " ) ; asm volatile ( " pop w7 " );
? 2008-2011 microchip technology inc. ds39927c-page 157 pic24f16ka102 family 19.2.4 rtcc control registers register 19-1: rcfgcal: rtcc calibration and configuration register ( 1 ) r/w-0 u-0 r/w-0 r-0, hsc r-0, hsc r/w-0 r/w-0 r/w-0 rtcen ( 2 ) ? rtcwren rtcsync halfsec ( 3 ) rtcoe rtcptr1 rtcptr0 bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cal7 cal6 cal5 cal4 cal3 cal2 cal1 cal0 bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 rtcen: rtcc enable bit ( 2 ) 1 = rtcc module is enabled 0 = rtcc module is disabled bit 14 unimplemented: read as ? 0 ? bit 13 rtcwren: rtcc value registers write enable bit 1 = rtcvalh and rtcvall registers can be written to by the user 0 = rtcvalh and rtcvall registers are locked out from being written to by the user bit 12 rtcsync: rtcc value registers read synchronization bit 1 = rtcvalh, rtcvall and alcfgrpt registers can change while reading due to a rollover ripple, resulting in an invalid data read. if the register is read twice and results in the same data, the data can be assumed to be valid. 0 = rtcvalh, rtcvall or alcfgrpt registers can be read without concern over a rollover ripple bit 11 halfsec: half second status bit ( 3 ) 1 = second half period of a second 0 = first half period of a second bit 10 rtcoe: rtcc output enable bit 1 = rtcc output is enabled 0 = rtcc output is disabled bit 9-8 rtcptr<1:0>: rtcc value register window pointer bits points to the corresponding rtcc value registers when reading the rtcvalh and rtcvall registers. the rtcptr<1:0> value decrements on every read or write of rtcvalh until it reaches ? 00 ?. rtcval<15:8>: 00 = minutes 01 = weekday 10 = month 11 = reserved rtcval<7:0>: 00 = seconds 01 = hours 10 = day 11 = year note 1: the rcfgcal register is only affected by a por. 2: a write to the rtcen bit is only allowed when rtcwren = 1 . 3: this bit is read-only; it is cleared to ? 0 ? on a write to the lower half of the minsec register.
pic24f16ka102 family ds39927c-page 158 ? 2008-2011 microchip technology inc. bit 7-0 cal<7:0>: rtc drift calibration bits 01111111 = maximum positive adjustment; adds 508 rtc clock pulses every one minute . . . 01111111 = minimum positive adjustment; adds 4 rtc clock pulses every one minute 00000000 = no adjustment 11111111 = minimum negative adjustment; subtracts 4 rtc clock pulses every one minute . . . 10000000 = maximum negative adjustment; subtracts 512 rtc clock pulses every one minute register 19-1: rcfgcal: rtcc calibration and configuration register ( 1 ) (continued) note 1: the rcfgcal register is only affected by a por. 2: a write to the rtcen bit is only allowed when rtcwren = 1 . 3: this bit is read-only; it is cleared to ? 0 ? on a write to the lower half of the minsec register. register 19-2: padcfg1: pad co nfiguration control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 ? ? ? smbusdel oc1tris rtsecsel1 ( 1 ) rtsecsel0 ( 1 ) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-5 unimplemented: read as ? 0 ? bit 4-3 described in section 15.0 ?output compare? and section 17.0 ?inter-integrated circuit (i 2 c?)? . bit 2-1 rtsecsel<1:0>: rtcc seconds clock output select bits ( 1 ) 11 = reserved; do not use 10 = rtcc source clock is selected for the rtcc pin (can be lprc or sosc, depending on the rtcosc (fds<5>) bit setting) 01 = rtcc seconds clock is selected for the rtcc pin 00 = rtcc alarm pulse is selected for the rtcc pin bit 0 unimplemented: read as ? 0 ? note 1: to enable the actual rtcc output, the rtcoe (rcfgcal<10>) bit needs to be set.
? 2008-2011 microchip technology inc. ds39927c-page 159 pic24f16ka102 family register 19-3: alcfgrpt: al arm configuration register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 alrmen chime amask3 amask2 amask1 amask0 alrmptr1 alrmptr0 bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 arpt7 arpt6 arpt5 arpt4 arpt3 arpt2 arpt1 arpt0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 alrmen: alarm enable bit 1 = alarm is enabled (cleared automatically after an alarm event whenever arpt<7:0> = 00h and chime = 0 ) 0 = alarm is disabled bit 14 chime: chime enable bit 1 = chime is enabled; arpt<7:0> bits are allowed to roll over from 00h to ffh 0 = chime is disabled; arpt<7:0> bits stop once they reach 00h bit 13-10 amask<3:0>: alarm mask configuration bits 0000 = every half second 0001 = every second 0010 = every 10 seconds 0011 = every minute 0100 = every 10 minutes 0101 = every hour 0110 = once a day 0111 = once a week 1000 = once a month 1001 = once a year (except when configured for february 29 th , once every 4 years) 101x = reserved ? do not use 11xx = reserved ? do not use bit 9-8 alrmptr<1:0>: alarm value register window pointer bits points to the corresponding alarm value registers when reading the alrmvalh and alrmvall registers. the alrmptr<1:0> value decrements on every read or write of alrmvalh until it reaches ? 00 ?. alrmval<15:8>: 00 = alrmmin 01 = alrmwd 10 = alrmmnth 11 = unimplemented alrmval<7:0>: 00 = alrmsec 01 = alrmhr 10 = alrmday 11 = unimplemented bit 7-0 arpt<7:0>: alarm repeat counter value bits 11111111 = alarm will repeat 255 more times . . . 00000000 = alarm will not repeat the counter decrements on any alarm event; it is prevented from rolling over from 00h to ffh unless chime = 1 .
pic24f16ka102 family ds39927c-page 160 ? 2008-2011 microchip technology inc. 19.2.5 rtcval register mappings register 19-4: year: year value register ( 1 ) u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x yrten3 yrten2 yrten2 yrten1 yrone3 yrone2 yrone1 yrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7-4 yrten<3:0>: binary coded decimal value of year?s tens digit bits contains a value from 0 to 9. bit 3-0 yrone<3:0>: binary coded decimal value of year?s ones digit bits contains a value from 0 to 9. note 1: a write to the year register is only allowed when rtcwren = 1 . register 19-5: mthdy: month and day value register ( 1 ) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? mthten0 mthone3 mthone2 mthone1 mthone0 bit 15 bit 8 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? dayten1 dayten0 dayone3 dayone2 dayone1 dayone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12 mthten0: binary coded decimal value of month?s tens digit bit contains a value of ? 0 ? or ? 1 ?. bit 11-8 mthone<3:0>: binary coded decimal value of month?s ones digit bits contains a value from 0 to 9. bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dayten<1:0>: binary coded decimal value of day?s tens digit bits contains a value from 0 to 3. bit 3-0 dayone<3:0>: binary coded decimal value of day?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
? 2008-2011 microchip technology inc. ds39927c-page 161 pic24f16ka102 family register 19-6: wkdyhr: weekday and hours value register ( 1 ) u-0 u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x ? ? ? ? ? wday2 wday1 wday0 bit 15 bit 8 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? hrten1 hrten0 hrone3 hrone2 hrone1 hrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-11 unimplemented: read as ? 0 ? bit 10-8 wday<2:0>: binary coded decimal value of weekday digit bits contains a value from 0 to 6. bit 7-6 unimplemented: read as ? 0 ? bit 5-4 hrten<1:0>: binary coded decimal value of hour?s tens digit bits contains a value from 0 to 2. bit 3-0 hrone<3:0>: binary coded decimal value of hour?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 19-7: minsec: minutes and seconds value register u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? minten2 minten1 minten0 minone3 minone2 minone1 minone0 bit 15 bit 8 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? secten2 secten1 secten0 secone3 secone2 secone1 secone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 minten<2:0>: binary coded decimal value of minute?s tens digit bits contains a value from 0 to 5. bit 11-8 minone<3:0>: binary coded decimal value of minute?s ones digit bits contains a value from 0 to 9. bit 7 unimplemented: read as ? 0 ? bit 6-4 secten<2:0>: binary coded decimal value of second?s tens digit bits contains a value from 0 to 5. bit 3-0 secone<3:0>: binary coded decimal value of second?s ones digit bits contains a value from 0 to 9.
pic24f16ka102 family ds39927c-page 162 ? 2008-2011 microchip technology inc. 19.2.6 alrmval register mappings register 19-8: almthdy: alarm month and day value register ( 1) u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? mthten0 mthone3 mthone2 mthone1 mthone0 bit 15 bit 8 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? dayten1 dayten0 dayone3 dayone2 dayone1 dayone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12 mthten0: binary coded decimal value of month?s tens digit bit contains a value of ? 0 ? or ? 1 ?. bit 11-8 mthone<3:0>: binary coded decimal value of month?s ones digit bits contains a value from 0 to 9. bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dayten<1:0>: binary coded decimal value of day?s tens digit bits contains a value from 0 to 3. bit 3-0 dayone<3:0>: binary coded decimal value of day?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 . register 19-9: alwdhr: alarm weekday and hours value register ( 1 ) u-0 u-0 u-0 u-0 u-0 r/w-x r/w-x r/w-x ? ? ? ? ? wday2 wday1 wday0 bit 15 bit 8 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? hrten1 hrten0 hrone3 hrone2 hrone1 hrone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-11 unimplemented: read as ? 0 ? bit 10-8 wday<2:0>: binary coded decimal value of weekday digit bits contains a value from 0 to 6. bit 7-6 unimplemented: read as ? 0 ? bit 5-4 hrten<1:0>: binary coded decimal value of hour?s tens digit bits contains a value from 0 to 2. bit 3-0 hrone<3:0>: binary coded decimal value of hour?s ones digit bits contains a value from 0 to 9. note 1: a write to this register is only allowed when rtcwren = 1 .
? 2008-2011 microchip technology inc. ds39927c-page 163 pic24f16ka102 family register 19-10: alminsec: alarm mi nutes and seconds value register u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? minten2 minten1 minten0 minone3 minone2 minone1 minone0 bit 15 bit 8 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? secten2 secten1 secten0 secone3 secone2 secone1 secone0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 minten<2:0>: binary coded decimal value of minute?s tens digit bits contains a value from 0 to 5. bit 11-8 minone<3:0>: binary coded decimal value of minute?s ones digit bits contains a value from 0 to 9. bit 7 unimplemented: read as ? 0 ? bit 6-4 secten<2:0>: binary coded decimal value of second?s tens digit bits contains a value from 0 to 5. bit 3-0 secone<3:0>: binary coded decimal value of second?s ones digit bits contains a value from 0 to 9.
pic24f16ka102 family ds39927c-page 164 ? 2008-2011 microchip technology inc. 19.3 calibration the real-time crystal input can be calibrated using the periodic auto-adjust feature. when properly calibrated, the rtcc can provide an error of less than 3 seconds per month. this is accomplished by finding the number of error clock pulses and storing the value into the lower half of the rcfgcal register. the 8-bit signed value loaded into the lower half of rcfgcal is multiplied by four and will either be added or subtracted from the rtcc timer, once every minute. refer to the steps below for rtcc calibration: 1. using another timer resource on the device, the user must find the error of the 32.768 khz crystal. 2. once the error is known, it must be converted to the number of error clock pulses per minute. 3. a) if the oscillator is faster than ideal (negative result form step 2), the rcfgcal register value must be negative. this causes the specified number of clock pulses to be subtracted from the timer counter, once every minute. b) if the oscillator is slower than ideal (positive result from step 2), the rcfgcal register value must be positive. this causes the specified number of clock pulses to be subtracted from the timer counter, once every minute. divide the number of error clocks, per minute by 4, to get the correct calibration value and load the rcfgcal register with the correct value. (each 1-bit increment in the calibration adds or subtracts 4 pulses). equation 19-1: writes to the lower half of the rcfgcal register should only occur when the timer is turned off, or immediately after the rising edge of the seconds pulse. 19.4 alarm ? configurable from half second to one year ? enabled using the alrmen bit (alcfgrpt<15>) ? one-time alarm and repeat alarm options available 19.4.1 configuring the alarm the alarm feature is enabled using the alrmen bit. this bit is cleared when an alarm is issued. writes to alrmval should only take place when alrmen = 0 . as displayed in figure 19-2 , the interval selection of the alarm is configured through the amask bits (alcfgrpt<13:10>). these bits determine which and how many digits of the alarm must match the clock value for the alarm to occur. the alarm can also be configured to repeat based on a preconfigured interval. the amount of times this occurs, once the alarm is enabled, is stored in the arpt<7:0> bits (alcfgrpt<7:0>). when the value of the arpt bits equals 00h and the chime bit (alcfgrpt<14>) is cleared, the repeat function is disabled and only a single alarm will occur. the alarm can be repeated, up to 255 times, by loading arpt<7:0> with ffh. after each alarm is issued, the value of the arpt bits is decremented by one. once the value has reached 00h, the alarm will be issued one last time, after which, the alrmen bit will be cleared automatically and the alarm will turn off. indefinite repetition of the alarm can occur if the chime bit = 1 . instead of the alarm being disabled when the value of the arpt bits reaches 00h, it rolls over to ffh and continues counting indefinitely while chime is set. 19.4.2 alarm interrupt at every alarm event, an interrupt is generated. in addition, an alarm pulse output is provided that operates at half the frequency of the alarm. this output is completely synchronous to the rtcc clock and can be used as a trigger clock to other peripherals. (ideal frequency ? ? measured frequency) * 60 = clocks per minute ? ideal frequency = 32,768 hz note: it is up to the user to include in the error value, the initial error of the crystal; drift due to temperature and drift due to crystal aging. note: changing any of the registers, other than the rcfgcal and alcfgrpt registers, and the chime bit while the alarm is enabled (alrmen = 1 ), can result in a false alarm event leading to a false alarm interrupt. to avoid a false alarm event, the timer and alarm values should only be changed while the alarm is disabled (alrmen = 0 ). it is recommended that the alcfgrpt register and the chime bit be changed when rtcsync = 0 .
? 2008-2011 microchip technology inc. ds39927c-page 165 pic24f16ka102 family figure 19-2: alarm mask settings note 1: annually, except when configured for february 29. s ss mss mm s s hh mm ss dhhmmss dd hh mm s s mm d d h h mm s s day of the week month day hours minutes seconds alarm mask setting (amask<3:0>) 0000 - every half second 0001 - every second 0010 - every 10 seconds 0011 - every minute 0100 - every 10 minutes 0101 - every hour 0110 - every day 0111 - every week 1000 - every month 1001 - every year (1)
pic24f16ka102 family ds39927c-page 166 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 167 pic24f16ka102 family 20.0 programmable cyclic redundancy check (crc) generator the programmable cyclic redundancy check (crc) module in pic24f devices is a software-configurable crc checksum generator. the crc algorithm treats a message as a binary bit stream and divides it by a fixed binary number. the remainder from this division is considered the checksum. as in division, the crc calculation is also an iterative process. the only difference is that these operations are done on modulo arithmetic based on mod2. for example, division is replaced with the xor operation (i.e., subtraction without carry). the crc algorithm uses the term, polynomial, to perform all of its calculations. the divisor, dividend and remainder that are represented by numbers are termed as polynomials with binary coefficients. the programmable crc generator offers the following features: ? user-programmable polynomial crc equation ? interrupt output ? data fifo the module implements a software-configurable crc generator. the terms of the polynomial and its length can be programmed using the crcxor (x<15:1>) bits and the crccon (plen<3:0>) bits, respectively. consider the crc equation: equation 20-1: crc to program this polynomial into the crc generator, the crc register bits should be set as provided in table 20-1 . table 20-1: example crc setup the value of x<15:1>, the 12 th bit and the 5 th bit are set to ? 1 ?, as required by the equation. the 0 bit required by the equation is always xored. for a 16-bit polynomial, the 16 th bit is also always assumed to be xored; therefore, the x<15:1> bits do not have the 0 bit or the 16 th bit. the topology of a standard crc generator is displayed in figure 20-2 . figure 20-1: crc shifter details note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on program- mable cyclic redundancy check, refer to the ?pic24f family reference manual? , section 30. ?programmable cyclic redundancy check (crc)? (ds39714). bit name bit value plen<3:0> 1111 x<15:1> 000100000010000 x 16 + x 12 + x 5 + 1 in out bit 0 0 1 clk x1 in out bit 1 0 1 clk x2 in out bit 2 0 1 clk x3 in out bit 15 0 1 clk x15 xor d out 01 2 15 plen<3:0> hold hold hold hold crc read bus crc write bus crc shift register
pic24f16ka102 family ds39927c-page 168 ? 2008-2011 microchip technology inc. figure 20-2: crc generato r reconfigured for x 16 + x 12 + x 5 + 1 20.1 user interface 20.1.1 data interface to start serial shifting, a value of ? 1 ? must be written to the crcgo bit. the module incorporates a fifo that is 8-level deep when plen<3:0> > 7 and 16-deep, otherwise. the data for which the crc is to be calculated must first be written into the fifo. the smallest data element that can be written into the fifo is one byte. for example, if plen = 5, then the size of the data is plen + 1 = 6. the data must be written as follows: data<5:0> = crc_input <5:0> data<7:6> = bxx once data is written into the crcwdat msb (as defined by plen), the value of the vword bits (crccon<12:8>) increments by one. the serial shifter starts shifting data into the crc engine when crcgo = 1 and vword<4:0> > 0 . when the most significant bit (msb) is shifted out, the vword bits decrement by one. the serial shifter continues shifting until the vword bits reach zero. therefore, for a given value of plen, it will take (plen + 1) * vword number of clock cycles to complete the crc calculations. when the vword bits reach 8 (or 16), the crcful bit will be set. when the vword bits reach 0, the crcmpt bit will be set. to continually feed data into the crc engine, the recommended mode of operation is to initially ?prime? the fifo with a sufficient number of words so no interrupt is generated before the next word can be written. once that is done, start the crc by setting the crcgo bit to ? 1 ?. from that point onward, the vword bits should be polled. if they read less than 8 or 16, another word can be written into the fifo. to empty words already written into a fifo, the crcgo bit must be set to ? 1 ? and the crc shifter allowed to run until the crcmpt bit is set. also, to get the correct crc reading, it will be necessary to wait for the crcmpt bit to go high before reading the crcwdat register. if a word is written when the crcful bit is set, the vword pointer will roll over to 0. the hardware will then behave as if the fifo is empty. however, the condition to generate an interrupt will not be met; therefore, no interrupt will be generated (see section 20.1.2 ?interrupt operation? ). at least one instruction cycle must pass after a write to crcwdat before a read of the vword bits is done. 20.1.2 interrupt operation when the vword<4:0> bits make a transition from a value of ? 1 ? to ? 0 ?, an interrupt will be generated. 20.2 operation in power save modes 20.2.1 sleep mode if sleep mode is entered while the module is operating, the module will be suspended in its current state until clock execution resumes. 20.2.2 idle mode to continue full module operation in idle mode, the csidl bit must be cleared prior to entry into the mode. if csidl = 1 , the module will behave the same way as it does in sleep mode; pending interrupt events will be passed on, even though the module clocks are not available. d q bit 0 clk dq bit 4 clk dq bit 5 clk dq bit 12 clk xor sdox crc read bus crc write bus dq bit 15 clk
? 2008-2011 microchip technology inc. ds39927c-page 169 pic24f16ka102 family 20.3 registers there are four registers used to control programmable crc operation: ? crccon ? crcxor ? crcdat ? crcwdat register 20-1: crccon: crc control register u-0 u-0 r/w-0 r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc ? ? csidl vword4 vword3 vword2 vword1 vword0 bit 15 bit 8 r-0, hsc r-1, hsc u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 crcful crcmpt ? crcgo plen3 plen2 plen1 plen0 bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 csidl: crc stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-8 vword<4:0>: pointer value bits indicates the number of valid words in the fifo. has a maximum value of 8 when plen<3:0> > 7, or 16 when plen<3:0> ? ? 7. bit 7 crcful : fifo full bit 1 = fifo is full 0 = fifo is not full bit 6 crcmpt: fifo empty bit 1 = fifo is empty 0 = fifo is not empty bit 5 unimplemented: read as ? 0 ? bit 4 crcgo: start crc bit 1 = start crc serial shifter 0 = crc serial shifter is turned off bit 3-0 plen<3:0>: polynomial length bits denotes the length of the polynomial to be generated minus 1.
pic24f16ka102 family ds39927c-page 170 ? 2008-2011 microchip technology inc. register 20-2: crcxor: crc xor polynomial register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 x15 x14 x13 x12 x11 x10 x9 x8 bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 x7 x6 x5 x4 x3 x2 x1 ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-1 x<15:1>: xor of polynomial term x n enable bits bit 0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 171 pic24f16ka102 family 21.0 high/low-voltage detect (hlvd) the high/low-voltage detect module (hlvd) is a programmable circuit that allows the user to specify both the device voltage trip point and the direction of change. an interrupt flag is set if the device experiences an excursion past the trip point in the direction of change. if the interrupt is enabled, the program execution will branch to the interrupt vector address and the software can then respond to the interrupt. the hlvd control register (see register 21-1 ) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. figure 21-1: high/low-voltage de tect (hlvd) module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the high/low-voltage detect, refer to the ?pic24f family reference manual? , section 36. ?high-level integration with programmable high/low-voltage detect (hlvd)? (ds39725). set v dd 16-to-1 mux hlvden hlvdl<3:0> hlvdin v dd externally generated trip point hlvdif hlvden internal band gap voltage reference vdir 1.2v typical
pic24f16ka102 family ds39927c-page 172 ? 2008-2011 microchip technology inc. register 21-1: hlvdcon: high/low-v oltage detect control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 hlvden ?hlsidl ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 vdir bgvst irvst ? hlvdl3 hlvdl2 hlvdl1 hlvdl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 hlvden: high/low-voltage detect power enable bit 1 = hlvd is enabled 0 = hlvd is disabled bit 14 unimplemented: read as ? 0 ? bit 13 hlsidl: hlvd stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-8 unimplemented: read as ? 0 ? bit 7 vdir: voltage change direction select bit 1 = event occurs when voltage equals or exceeds trip point (hlvdl<3:0>) 0 = event occurs when voltage equals or falls below trip point (hlvdl<3:0>) bit 6 bgvst: band gap voltage stable flag bit 1 = indicates that the band gap voltage is stable 0 = indicates that the band gap voltage is unstable bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the internal reference voltage is stable and the high-voltage detect logic generates the interrupt flag at the specified voltage range 0 = indicates that the internal reference voltage is unstable and the high-voltage detect logic will not generate the interrupt flag at the specified voltage range, and the hlvd interrupt should not be enabled bit 4 unimplemented: read as ? 0 ? bit 3-0 hlvdl<3:0>: high/low-voltage detection limit bits 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = trip point 1 ( 1 ) 1101 = trip point 2 ( 1 ) 1100 = trip point 3 ( 1 ) . . . 0000 = trip point 15 ( 1 ) note 1: for actual trip point, refer to section 29.0 ?electrical characteristics? .
? 2008-2011 microchip technology inc. ds39927c-page 173 pic24f16ka102 family 22.0 10-bit high-speed a/d converter the 10-bit a/d converter has the following key features: ? successive approximation (sar) conversion ? conversion speeds of up to 500 ksps ? nine analog input pins ? external voltage reference input pins ? internal band gap reference inputs ? automatic channel scan mode ? selectable conversion trigger source ? 16-word conversion result buffer ? selectable buffer fill modes ? four result alignment options ? operation during cpu sleep and idle modes on all pic24f16ka102 family devices, the 10-bit a/d converter has nine analog input pins, designated an0 through an5 and an10 through an12. in addition, there are two analog input pins for external voltage reference connections (v ref + and v ref -). these voltage reference inputs may be shared with other analog input pins. a block diagram of the a/d converter is displayed in figure 22-1 . to perform an a/d conversion: 1. configure the a/d module: a) configure port pins as analog inputs and/or select band gap reference inputs (ad1pcfg<15:13>, ad1pcfg<9:6>). b) select voltage reference source to match expected range on analog inputs (ad1con2<15:13>). c) select the analog conversion clock to match the desired data rate with the processor clock (ad1con3<7:0>). d) select the appropriate sample/conversion sequence (ad1con1<7:5> and ad1con3<12:8>). e) select how conversion results are presented in the buffer (ad1con1<9:8>). f) select interrupt rate (ad1con2<5:2>). g) turn on a/d module (ad1con1<15>). 2. configure a/d interrupt (if required): a) clear the ad1if bit. b) select a/d interrupt priority. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the 10-bit high-speed a/d converter, refer to the ?pic24f family reference manual? , section 17. ?10-bit a/d converter? (ds39705).
pic24f16ka102 family ds39927c-page 174 ? 2008-2011 microchip technology inc. figure 22-1: 10-bit high-speed a/d converter block diagram comparator 10-bit sar conversion logic v ref + dac an12 an10 an11 an4 an5 an0 an1 an2 an3 v ref - sample control s/h av ss av dd adc1buf0: adc1buff ad1con1 ad1con2 ad1con3 ad1chs ad1pcfg control logic data formatting input mux control conversion control pin config control internal data bus 16 v r + v r - mux a mux b v inh v inl v inh v inh v inl v inl v bg v bg /2 ad1cssl v r + v r - v r select an1 an1
? 2008-2011 microchip technology inc. ds39927c-page 175 pic24f16ka102 family register 22-1: ad1con1: a/d control register 1 r/w-0 u-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 adon ( 1 ) ?adsidl ? ? ?form1form0 bit 15 bit 8 r/w -0 r/w -0 r/w-0 u-0 u-0 r/w-0 r/w -0, hsc r/w -0, hsc ssrc2 ssrc1 ssrc0 ? ? asam samp done bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 adon: a/d operating mode bit ( 1 ) 1 = a/d converter module is operating 0 = a/d converter is off bit 14 unimplemented: read as ? 0 ? bit 13 adsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-10 unimplemented: read as ? 0 ? bit 9-8 form<1:0>: data output format bits 11 = signed fractional ( sddd dddd dd00 0000 ) 10 = fractional ( dddd dddd dd00 0000 ) 01 = signed integer ( ssss sssd dddd dddd ) 00 = integer ( 0000 00dd dddd dddd ) bit 7-5 ssrc<2:0>: conversion trigger source select bits 111 = internal counter ends sampling and starts conversion (auto-convert) 110 = ctmu event ends sampling and starts conversion 101 = reserved 100 = reserved 011 = reserved 010 = timer3 compare ends sampling and starts conversion 001 = active transition on int0 pin ends sampling and starts conversion 000 = clearing samp bit ends sampling and starts conversion bit 4-3 unimplemented: read as ? 0 ? bit 2 asam: a/d sample auto-start bit 1 = sampling begins immediately after last conversion completes; samp bit is auto-set 0 = sampling begins when samp bit is set bit 1 samp: a/d sample enable bit 1 = a/d sample/hold amplifier is sampling input 0 = a/d sample/hold amplifier is holding bit 0 done: a/d conversion status bit 1 = a/d conversion is done 0 = a/d conversion is not done note 1: values of adc1bufn registers will not retain their values once the adon bit is cleared. read out the conversion values from the buffer before disabling the module.
pic24f16ka102 family ds39927c-page 176 ? 2008-2011 microchip technology inc. register 22-2: ad1con2: a/d control register 2 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 vcfg2 vcfg1 vcfg0 offcal ( 1 ) ? cscna ? ? bit 15 bit 8 r-0, hsc u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 bufs ? smpi3 smpi2 smpi1 smpi0 bufm alts bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 vcfg<2:0>: voltage reference configuration bits bit 12 offcal: offset calibration bit ( 1 ) 1 = converts to get the offset calibration value 0 = converts to get the actual input value bit 11 unimplemented: read as ? 0 ? bit 10 cscna: scan input selections for ch0+ s/h input for mux a input multiplexer setting bit 1 = scan inputs 0 = do not scan inputs bit 9-8 unimplemented: read as ? 0 ? bit 7 bufs: buffer fill status bit (valid only when bufm = 1 ) 1 = a/d is currently filling buffer, 08-0f; user should access data in 00-07 0 = a/d is currently filling buffer, 00-07; user should access data in 08-0f bit 6 unimplemented: read as ? 0 ? bit 5-2 smpi<3:0>: sample/convert sequences per interrupt selection bits 1111 = interrupts at the completion of conversion for each 16 th sample/convert sequence 1110 = interrupts at the completion of conversion for each 15 th sample/convert sequence . . . 0001 = interrupts at the completion of conversion for each 2 nd sample/convert sequence 0000 = interrupts at the completion of conversion for each sample/convert sequence note 1: when the offcal bit is set, inputs are disconnected and tied to av ss . this sets the inputs of the a/d to zero. then, the user can perform a conversion. use of the calibration mode is not affected by ad1pcfg contents nor channel input selection. any analog input switches are disconnected from the a/d converter in this mode. the conversion result is stored by the user software and used to compensate subsequent conversions. this can be done by adding the two?s complement of the result obtained with the offcal bit set to all normal a/d conversions. vcfg<2:0> v r +v r - 000 av dd av ss 001 external v ref + pin av ss 010 av dd external v ref - pin 011 external v ref + pin external v ref - pin 1xx av dd av ss
? 2008-2011 microchip technology inc. ds39927c-page 177 pic24f16ka102 family bit 1 bufm: buffer mode select bit 1 = buffer is configured as two 8-word buffers (adc1bufn<15:8> and adc1bufn<7:0>) 0 = buffer is configured as one 16-word buffer (adc1bufn<15:0>) bit 0 alts: alternate input sample mode select bit 1 = uses mux a input multiplexer settings for first sample, then alternates between mux b and mux a input multiplexer settings for all subsequent samples 0 = always uses mux a input multiplexer settings register 22-2: ad1con2: a/d control register 2 (continued) note 1: when the offcal bit is set, inputs are disconnected and tied to av ss . this sets the inputs of the a/d to zero. then, the user can perform a conversion. use of the calibration mode is not affected by ad1pcfg contents nor channel input selection. any analog input switches are disconnected from the a/d converter in this mode. the conversion result is stored by the user software and used to compensate subsequent conversions. this can be done by adding the two?s complement of the result obtained with the offcal bit set to all normal a/d conversions. register 22-3: ad1con3: a/d control register 3 r/w-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adrc ? ? samc4 samc3 samc2 samc1 samc0 bit 15 bit 8 u -0 u -0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 adrc: a/d conversion clock source bit 1 = a/d internal rc clock 0 = clock derived from system clock bit 14-13 unimplemented: read as ? 0 ? bit 12-8 samc<4:0>: auto-sample time bits 11111 = 31 t ad 00001 = 1 t ad 00000 = 0 t ad (not recommended) bit 7-6 unimplemented: read as ? 0 ? bit 5-0 adcs<5:0>: a/d conversion clock select bits 111111 = 64 ? t cy 111110 = 63 ? t cy 000001 = 3 ? t cy 000000 = 2 ? t cy
pic24f16ka102 family ds39927c-page 178 ? 2008-2011 microchip technology inc. - register 22-4: ad1chs: a/d input select register r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0nb ? ? ? ch0sb3 ch0sb2 ch0sb1 ch0sb0 bit 15 bit 8 r/w -0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0na ? ? ? ch0sa3 ch0sa2 ch0sa1 ch0sa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ch0nb: channel 0 negative input select for mux b multiplexer setting bit 1 = channel 0 negative input is an1 0 = channel 0 negative input is v r - bit 14-12 unimplemented: read as ? 0 ? bit 11-8 ch0sb<3:0>: channel 0 positive input select for mux b multiplexer setting bits 1111 = channel 0 positive input is band gap reference (v bg ) 1110 = channel 0 positive input is band gap, divided by two, reference (v bg /2) 1101 = no channels connected (actual a/d mux switch activates, but input floats); used for ctmu 1100 = channel 0 positive input is an12 1011 = channel 0 positive input is an11 1010 = channel 0 positive input is an10 1001 = reserved 1000 = reserved 0111 = av dd 0110 = av ss 0101 = channel 0 positive input is an5 0100 = channel 0 positive input is an4 0011 = channel 0 positive input is an3 0010 = channel 0 positive input is an2 0001 = channel 0 positive input is an1 0000 = channel 0 positive input is an0 bit 7 ch0na: channel 0 negative input select for mux a multiplexer setting bit 1 = channel 0 negative input is an1 0 = channel 0 negative input is v r - bit 6-4 unimplemented: read as ? 0 ? bit 3-0 ch0sa<3:0>: channel 0 positive input select for sample a bits 1111 = channel 0 positive input is band gap reference (v bg ) 1110 = channel 0 positive input is band gap, divided by two, reference (v bg /2) 1101 = no channels connected (actual a/d mux switch activates but input floats); used for ctmu 1100 = channel 0 positive input is an12 1011 = channel 0 positive input is an11 1010 = channel 0 positive input is an10 1001 = reserved 1000 = reserved 0111 = av dd 0110 = av ss 0101 = channel 0 positive input is an5 0100 = channel 0 positive input is an4 0011 = channel 0 positive input is an3 0010 = channel 0 positive input is an2 0001 = channel 0 positive input is an1 0000 = channel 0 positive input is an0
? 2008-2011 microchip technology inc. ds39927c-page 179 pic24f16ka102 family register 22-5: ad1pcfg: a/d port configuration register r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 pcfg15 pcfg14 ? pcfg12 pcfg11 pcfg10 ? ? bit 15 bit 8 u -0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? pcfg5 pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 pcfg15: analog input pin configuration control bit 1 = analog channel is disabled from input scan 0 = internal band gap (v bg ) channel is enabled for input scan bit 14 pcfg14: analog input pin configuration control bit 1 = analog channel is disabled from input scan 0 = internal v bg /2 channel is enabled for input scan bit 13 unimplemented: read as ? 0 ? bit 12-10 pcfg<12:10>: analog input pin configuration control bits 1 = pin for corresponding analog channel is configured in digital mode; i/o port read is enabled 0 = pin is configured in analog mode; i/o port read is disabled; a/d samples pin voltage bit 9-6 unimplemented: read as ? 0 ? bit 5-0 pcfg<5:0>: analog input pin configuration control bits 1 = pin for corresponding analog channel is configured in digital mode; i/o port read is enabled 0 = pin configured in analog mode; i/o port read is disabled; a/d samples pin voltage
pic24f16ka102 family ds39927c-page 180 ? 2008-2011 microchip technology inc. register 22-6: ad1cssl: a/d input scan select register (low) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 ? ? ? cssl12 cssl11 cssl10 ? ? bit 15 bit 8 u -0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? cssl5 cssl4 cssl3 cssl2 cssl1 cssl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12-10 cssl<12:10>: a/d input pin scan selection bits 1 = corresponding analog channel is selected for input scan 0 = analog channel omitted from input scan bit 9-6 unimplemented: read as ? 0 ? bit 5-0 cssl<5:0>: a/d input pin scan selection bits 1 = corresponding analog channel is selected for input scan 0 = analog channel omitted from input scan
? 2008-2011 microchip technology inc. ds39927c-page 181 pic24f16ka102 family equation 22-1: a/d conversion clock period (1) figure 22-2: 10-bit a/d converter analog input model note 1: based on t cy = 2 * t osc ; doze mode and pll are disabled. t ad = t cy ? (adcs + 1) t ad t cy adcs = ? 1 c pin va rs anx v t = 0.6v v t = 0.6v i leakage r ic ? 250 ? sampling switch r ss c hold = a/d capacitance v ss v dd = 4.4 pf (typical) 500 na legend: c pin v t i leakage r ic r ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch resistance = sample/hold capacitance (from a/d) various junctions note: c pin value depends on device package and is not tested. effect of c pin negligible if rs ? 5 k ? . r ss ? 5 k ? (typical) 6-11 pf (typical)
pic24f16ka102 family ds39927c-page 182 ? 2008-2011 microchip technology inc. figure 22-3: a/d transfer function 10 0000 0001 (513) 10 0000 0010 (514) 10 0000 0011 (515) 01 1111 1101 (509) 01 1111 1110 (510) 01 1111 1111 (511) 11 1111 1110 (1022) 11 1111 1111 (1023) 00 0000 0000 (0) 00 0000 0001 (1) output code 10 0000 0000 (512) (v inh ? v inl ) v r - v r + ? v r - 1024 512 * (v r + ? v r -) 1024 v r + v r - + v r - + 1023 * (v r + ? v r -) 1024 v r - + 0 (binary (decimal)) voltage level
? 2008-2011 microchip technology inc. ds39927c-page 183 pic24f16ka102 family 23.0 comparator module the comparator module provides two dual input comparators. the inputs to the comparator can be configured to use any one of four external analog inputs, as well as a voltage reference input from either the internal band gap reference, divided by 2 (v bg /2), or the comparator voltage reference generator. the comparator outputs may be directly connected to the cxout pins. when the respective coe equals ? 1 ?, the i/o pad logic makes the unsynchronized output of the comparator available on the pin. a simplified block diagram of the module is displayed in figure 23-1 . diagrams of the possible individual comparator configurations are displayed in figure 23-2 . each comparator has its own control register, cmxcon ( register 23-1 ), for enabling and configuring its operation. the output and event status of all three comparators is provided in the cmstat register ( register 23-2 ). figure 23-1: comparator module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the comparator module, refer to the ?pic24f family reference manual? , section 46. ?scalable comparator module? (ds39734). c1 v in - v in + c x inb c x inc c x ina c x ind cv ref v bg /2 c2 v in - v in + coe c1out pin cpol trigger/interrupt logic cevt evpol<1:0> cout input select logic cch<1:0> cref coe c2out pin cpol trigger/interrupt logic cevt evpol<1:0> cout
pic24f16ka102 family ds39927c-page 184 ? 2008-2011 microchip technology inc. figure 23-2: individual comparator configurations cx v in - v in + off (read as ? 0 ?) comparator off con = 0 , cref = x , cch<1:0> = xx comparator cxinb < cxina compare con = 1 , cref = 0 , cch<1:0> = 00 coe cxout cx v in - v in + coe c x inb c x ina comparator cxind < cxina compare con = 1 , cref = 0 , cch<1:0> = 10 cx v in - v in + coe cxout c x ind c x ina comparator cxinc < cxina compare con = 1 , cref = 0 , cch<1:0> = 01 cx v in - v in + coe c x inc c x ina comparator v bg /2 < cxina compare con = 1 , cref = 0 , cch<1:0> = 11 cx v in - v in + coe v bg /2 c x ina comparator cxinb < cv ref compare con = 1 , cref = 1 , cch<1:0> = 00 cx v in - v in + coe c x inb cv ref comparator cxind < cv ref compare con = 1 , cref = 1 , cch<1:0> = 10 cx v in - v in + coe c x ind cv ref comparator cxinc < cv ref compare con = 1 , cref = 1 , cch<1:0> = 01 cx v in - v in + coe c x inc cv ref comparator v bg /2 < cv ref compare con = 1 , cref = 1 , cch<1:0> = 11 cx v in - v in + coe v bg /2 cv ref pin pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin cxout pin - - - - -- - - -
? 2008-2011 microchip technology inc. ds39927c-page 185 pic24f16ka102 family register 23-1: cmxcon: comp arator x control registers r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 r-0 con coe cpol clpwr ? ? cevt cout bit 15 bit 8 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 r/w-0 r/w-0 evpol1 evpol0 ? cref ? ? cch1 cch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 con: comparator enable bit 1 = comparator is enabled 0 = comparator is disabled bit 14 coe: comparator output enable bit 1 = comparator output is present on the cxout pin 0 = comparator output is internal only bit 13 cpol: comparator output polarity select bit 1 = comparator output is inverted 0 = comparator output is not inverted bit 12 clpwr: comparator low-power mode select bit 1 = comparator operates in low-power mode 0 = comparator does not operate in low-power mode bit 11-10 unimplemented: read as ? 0 ? bit 9 cevt: comparator event bit 1 = comparator event defined by evpol<1:0> has occurred; subsequent triggers and interrupts are disabled until the bit is cleared 0 = comparator event has not occurred bit 8 cout: comparator output bit when cpol = 0 : 1 =v in + > v in - 0 =v in + < v in - when cpol = 1 : 1 =v in + < v in - 0 =v in + > v in - bit 7-6 evpol<1:0>: trigger/event/interrupt polarity select bits 11 = trigger/event/interrupt is generated on any change of the comparator output (while cevt = 0 ) 10 = trigger/event/interrupt is generated on transition of the comparator output: if cpol = 0 (non-inverted polarity): high-to-low transition only. if cpol = 1 (inverted polarity): low-to-high transition only. 01 = trigger/event/interrupt is generated on transition of the comparator output: if cpol = 0 (non-inverted polarity): low-to-high transition only. if cpol = 1 (inverted polarity): high-to-low transition only. 00 = trigger/event/interrupt generation is disabled
pic24f16ka102 family ds39927c-page 186 ? 2008-2011 microchip technology inc. bit 5 unimplemented: read as ? 0 ? bit 4 cref: comparator reference select bit (non-inverting input) 1 = non-inverting input connects to the internal cv ref voltage 0 = non-inverting input connects to the cxina pin bit 3-2 unimplemented: read as ? 0 ? bit 1-0 cch<1:0>: comparator channel select bits 11 = inverting input of comparator connects to v bg /2 10 = inverting input of comparator connects to cxind pin 01 = inverting input of comparator connects to cxinc pin 00 = inverting input of comparator connects to cxinb pin register 23-1: cmxcon: comparator x control registers (continued) register 23-2: cmstat: comparat or module status register r/w-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc r-0, hsc cmidl ? ? ? ? ? c2evt c1evt bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc r-0, hsc ? ? ? ? ? ? c2out c1out bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 cmidl: comparator stop in idle mode bit 1 = disable comparator interrupts when the device enters idle mode; the module is still enabled 0 = continue operation of all enabled comparators in idle mode bit 14-10 unimplemented: read as ? 0 ? bit 9 c2evt: comparator 2 event status bit (read-only) shows the current event status of comparator 2 (cm2con<9>). bit 8 c1evt: comparator 1 event status bit (read-only) shows the current event status of comparator 1 (cm1con<9>). bit 7-2 unimplemented: read as ? 0 ? bit 1 c2out: comparator 2 output status bit (read-only) shows the current output of comparator 2 (cm2con<8>). bit 0 c1out: comparator 1 output status bit (read-only) shows the current output of comparator 1 (cm1con<8>).
? 2008-2011 microchip technology inc. ds39927c-page 187 pic24f16ka102 family 24.0 comparator voltage reference 24.1 configuring the comparator voltage reference the comparator voltage reference module is controlled through the cvrcon register ( register 24-1 ). the comparator voltage reference provides two ranges of output voltage, each with 16 distinct levels. the range to be used is selected by the cvrr bit (cvrcon<5>). the primary difference between the ranges is the size of the steps selected by the cv ref selection bits (cvr<3:0>), with one range offering finer resolution. the comparator reference supply voltage can come from either v dd and v ss , or the external v ref + and v ref -. the voltage source is selected by the cvrss bit (cvrcon<4>). the settling time of the comparator voltage reference must be considered when changing the cv ref output. figure 24-1: comparator volt age reference block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the comparator voltage reference, refer to the ?pic24f family reference manual? , section 20. ?comparator voltage reference module? (ds39709). 16-to-1 mux cvr<3:0> 8r r cvren cvrss = 0 av dd v ref + cvrss = 1 8r cvrss = 0 v ref - cvrss = 1 r r r r r r 16 steps cvrr cv ref av ss
pic24f16ka102 family ds39927c-page 188 ? 2008-2011 microchip technology inc. register 24-1: cvrcon: comparator vo ltage reference control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 cvren: comparator voltage reference enable bit 1 =cv ref circuit is powered on 0 =cv ref circuit is powered down bit 6 cvroe: comparator v ref output enable bit 1 =cv ref voltage level is output on cv ref pin 0 =cv ref voltage level is disconnected from cv ref pin bit 5 cvrr: comparator v ref range selection bit 1 =cv rsrc range should be 0 to 0.625 cv rsrc with cv rsrc /24 step size 0 =cv rsrc range should be 0.25 to 0.719 cv rsrc with cv rsrc /32 step size bit 4 cvrss: comparator v ref source selection bit 1 = comparator reference source, cv rsrc = v ref + ? v ref - 0 = comparator reference source, cv rsrc = av dd ? av ss bit 3-0 cvr3:cvr0: comparator v ref value selection 0 ? cvr<3:0> ? 15 bits w hen cvrr = 1 and cvrss = 0 : cv ref = (cvr<3:0>/24) * (cv rsrc ) w hen cvrr = 0 and cvrss = 0 : cv ref = 1/4 (cv rsrc ) + (cvr<3:0>/32) * (cv rsrc ) w hen cvrr = 1 and cvrss = 1 : cv ref = ((cvr<3:0>/24) * (cv rsrc )) + v ref - w hen cvrr = 0 and cvrss = 1 : cv ref = (1/4 (cv rsrc ) + (cvr<3:0>/32) * (cv rsrc )) + v ref -
? 2008-2011 microchip technology inc. ds39927c-page 189 pic24f16ka102 family 25.0 charge time measurement unit (ctmu) the charge time measurement unit (ctmu) is a flexible analog module that provides charge measure- ment, accurate differential time measurement between pulse sources and asynchronous pulse generation. its key features include: ? four-edge input trigger sources ? polarity control for each edge source ? control of edge sequence ? control of response to edges ? time measurement resolution of one nanosecond ? accurate current source suitable for capacitive measurement together with other on-chip analog modules, the ctmu can be used to precisely measure time, measure capacitance, measure relative changes in capacitance, or generate output pulses that are independent of the system clock. the ctmu module is ideal for interfacing with capacitive-based touch sensors. the ctmu is controlled through two registers: ctmucon and ctmuicon. ctmucon enables the module, and controls edge source selection, edge source polarity selection, and edge sequencing. the ctmuicon register selects the current range of current source and trims the current. 25.1 measuring capacitance the ctmu module measures capacitance by generating an output pulse with a width equal to the time between edge events on two separate input chan- nels. the pulse edge events to both input channels can be selected from four sources: two internal peripheral modules (oc1 and timer1) and two external pins (cted1 and cted2). this pulse is used with the mod- ule?s precision current source to calculate capacitance according to the relationship: for capacitance measurements, the a/d converter samples an external capacitor (c app ) on one of its input channels, after the ctmu output?s pulse. a precision resistor (r pr ) provides current source calibration on a second a/d channel. after the pulse ends, the converter determines the voltage on the capacitor. the actual calculation of capacitance is performed in software by the application. figure 25-1 displays the external connections used for capacitance measurements, and how the ctmu and a/d modules are related in this application. this example also shows the edge events coming from timer1, but other configurations using external edge sources are possible. a detailed discussion on measuring capaci- tance and time with the ctmu module is provided in the ? pic24f family reference manual? . figure 25-1: typical connections and internal configuration for capacitance measurement note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the charge measurement unit, refer to the ?pic24f family reference manual? , section 11. ?charge time measurement unit (ctmu)? (ds39724). i = c ? dv dt pic24f device a/d converter ctmu anx c app output pulse edg1 edg2 r pr an y timer1 current source
pic24f16ka102 family ds39927c-page 190 ? 2008-2011 microchip technology inc. 25.2 measuring time time measurements on the pulse width can be similarly performed using the a/d module?s internal capacitor (c ad ) and a precision resistor for current calibration. figure 25-2 displays the external connections used for time measurements, and how the ctmu and a/d modules are related in this application. this example also shows both edge events coming from the external cted pins, but other configurations using internal edge sources are possible. 25.3 pulse generation and delay the ctmu module can also generate an output pulse with edges that are not synchronous with the device?s system clock. more specifically, it can generate a pulse with a programmable delay from an edge event input to the module. when the module is configured for pulse generation delay by setting the tgen bit (ctmucon<12>), the internal current source is connected to the b input of comparator 2. a capacitor (c delay ) is connected to the comparator 2 pin, c2inb, and the comparator voltage reference, cv ref , is connected to c2ina. cv ref is then configured for a specific trip point. the module begins to charge c delay when an edge event is detected. when c delay charges above the cv ref trip point, a pulse is output on ctpls. the length of the pulse delay is determined by the value of c delay and the cv ref trip point. figure 25-3 shows the external connections for pulse generation, as well as the relationship of the different analog modules required. while cted1 is shown as the input pulse source, other options are available. a detailed discussion on pulse generation with the ctmu module is provided in the ? pic24f family reference manual? . figure 25-2: typical connections and internal configuration for time measurement figure 25-3: typical connections and internal configuration for pulse delay generation pic24f device a/d converter ctmu cted1 cted2 anx output pulse edg1 edg2 c ad r pr current source c2 cv ref ctpls pic24f device current source comparator ctmu cted1 c2inb c delay edg1 -
? 2008-2011 microchip technology inc. ds39927c-page 191 pic24f16ka102 family register 25-1: ctmucon: ctmu control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 edg2pol edg2sel1 edg2sel0 edg1pol ed g1sel1 edg1sel0 edg2stat edg1stat bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ctmuen: ctmu enable bit 1 = module is enabled 0 = module is disabled bit 14 unimplemented: read as ? 0 ? bit 13 ctmusidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12 tgen: time generation enable bit 1 = enables edge delay generation 0 = disables edge delay generation bit 11 edgen: edge enable bit 1 = edges are not blocked 0 = edges are blocked bit 10 edgseqen: edge sequence enable bit 1 = edge 1 event must occur before edge 2 event can occur 0 = no edge sequence is needed bit 9 idissen: analog current source control bit 1 = analog current source output is grounded 0 = analog current source output is not grounded bit 8 cttrig: trigger control bit 1 = trigger output is enabled 0 = trigger output is disabled bit 7 edg2pol: edge 2 polarity select bit 1 = edge 2 is programmed for a positive edge response 0 = edge 2 is programmed for a negative edge response bit 6-5 edg2sel<1:0>: edge 2 source select bits 11 = cted1 pin 10 = cted2 pin 01 = oc1 module 00 = timer1 module bit 4 edg1pol: edge 1 polarity select bit 1 = edge 1 is programmed for a positive edge response 0 = edge 1 is programmed for a negative edge response
pic24f16ka102 family ds39927c-page 192 ? 2008-2011 microchip technology inc. bit 3-2 edg1sel<1:0>: edge 1 source select bits 11 = cted1 pin 10 = cted2 pin 01 = oc1 module 00 = timer1 module bit 1 edg2stat: edge 2 status bit 1 = edge 2 event has occurred 0 = edge 2 event has not occurred bit 0 edg1stat: edge 1 status bit 1 = edge 1 event has occurred 0 = edge 1 event has not occurred register 25-1: ctmuco n: ctmu control register (continued) register 25-2: ctmuicon: ctmu current control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-10 itrim<5:0>: current source trim bits 011111 = maximum positive change from nominal current 011110 . . . 000001 = minimum positive change from nominal current 000000 = nominal current output specified by irng<1:0> 111111 = minimum negative change from nominal current . . . 100010 100000 = maximum negative change from nominal current bit 9-8 irng<1:0>: current source range select bits 11 = 100 ? base current 10 = 10 ? base current 01 = base current level (0.55 ? a nominal) 00 = current source is disabled bit 7-0 unimplemented: read as ? 0 ?
? 2008-2011 microchip technology inc. ds39927c-page 193 pic24f16ka102 family 26.0 special features pic24f16ka102 family devices include several features intended to maximize application flexibility and reliability, and minimize cost through elimination of external components. these are: ? flexible configuration ? watchdog timer (wdt) ? code protection ? in-circuit serial programming? (icsp?) ? in-circuit emulation 26.1 configuration bits the configuration bits can be programmed (read as ? 0 ?), or left unprogrammed (read as ? 1 ?), to select various device configurations. these bits are mapped, starting at program memory location, f80000h. a complete list is provided in table 26-1 . a detailed explanation of the various bit functions is provided in register 26-1 through register 26-8 . the address, f80000h, is beyond the user program memory space. in fact, it belongs to the configuration memory space (800000h-ffffffh), which can only be accessed using table reads and table writes. table 26-1: configuration registers locations register 26-1: fbs: boot se gment configuration register note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive refer- ence source. for more information on the watchdog timer, high-level device inte- gration and programming diagnostics, refer to the individual sections of the ?pic24f family reference manual? provided below : ? section 9. ?watchdog timer (wdt)? (ds39697) ? section 36. ?high-level integration with programmable high/ low-voltage detect (hlvd)? (ds39725) ? section 33. ?programming and diagnostics? (ds39716) configuration register address fbs f80000 fgs f80004 foscsel f80006 fosc f80008 fwdt f8000a fpor f8000c ficd f8000e fds f80010 u-0 u-0 u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 ? ? ? ? bss2 bss1 bss0 bwrp bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented: read as ? 0 ? bit 3-1 bss<2:0>: boot segment program flash code protection bits 111 = no boot program flash segment 011 = reserved 110 = standard security, boot program flash segment starts at 200h, ends at 000afeh 010 = high-security boot program flash segment starts at 200h, ends at 000afeh 101 = standard security, boot program flash segment starts at 200h, ends at 0015feh ( 1 ) 001 = high-security, boot program flash segment starts at 200h, ends at 0015feh ( 1 ) 100 = reserved 000 = reserved bit 0 bwrp: boot segment program flash write protection bit 1 = boot segment may be written 0 = boot segment is write-protected note 1: this selection should not be used in pic24f08ka1xx devices.
pic24f16ka102 family ds39927c-page 194 ? 2008-2011 microchip technology inc. register 26-2: fgs: general se gment configuration register register 26-3: foscsel: oscillator selection configuration register u-0 u-0 u-0 u-0 u-0 u-0 r/c-1 r/c-1 ? ? ? ? ? ? gss0 gwrp bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1 gss0: general segment code flash code protection bit 1 = no protection 0 = standard security is enabled bit 0 gwrp : general segment code flash write protection bit 1 = general segment may be written 0 = general segment is write-protected r/p-1 u-0 u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 ieso ? ? ? ? fnosc2 fnosc1 fnosc0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ieso: internal external switchover bit 1 = internal external switchover mode is enabled (two-speed start-up is enabled) 0 = internal external switchover mode is disabled (two-speed start-up is disabled) bit 6-3 unimplemented: read as ? 0 ? bit 2-0 fnosc<2:0>: oscillator selection bits 000 = fast rc oscillator (frc) 001 = fast rc oscillator with divide-by-n with pll module (frcdiv+pll) 010 = primary oscillator (xt, hs, ec) 011 = primary oscillator with pll module (hs+pll, ec+pll) 100 = secondary oscillator (sosc) 101 = low-power rc oscillator (lprc) 110 = 500 khz low-power frc oscillator with divide-by-n (lpfrcdiv) 111 = 8 mhz frc oscillator with divide-by-n (frcdiv)
? 2008-2011 microchip technology inc. ds39927c-page 195 pic24f16ka102 family register 26-4: fosc: oscilla tor configuration register r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 fcksm1 fcksm0 soscsel poscfreq1 poscfreq0 osciofnc poscmd1 poscmd0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fcksm<1:0>: clock switching and monitor selection configuration bits 1x = clock switching is disabled, fail-safe clock monitor is disabled 01 = clock switching is enabled, fail-safe clock monitor is disabled 00 = clock switching is enabled, fail-safe clock monitor is enabled bit 5 soscsel: secondary oscillator select bit 1 = secondary oscillator is configured for high-power operation 0 = secondary oscillator is configured for low-power operation bit 4-3 poscfreq<1:0>: primary oscillator frequency range configuration bits 11 = primary oscillator/external clock input frequency is greater than 8 mhz 10 = primary oscillator/external clock input frequency is between 100 khz and 8 mhz 01 = primary oscillator/external clock input frequency is less than 100 khz 00 = reserved; do not use bit 2 osciofnc: clko enable configuration bit 1 = clko output signal active on the osco pin; primary oscillator must be disabled or configured for the external clock mode (ec) for the clko to be active (poscmd<1:0> = 11 or 00 ) 0 = clko output is disabled bit 1-0 poscmd<1:0>: primary oscillator configuration bits 11 = primary oscillator mode is disabled 10 = hs oscillator mode is selected 01 = xt oscillator mode is selected 00 = external clock mode is selected
pic24f16ka102 family ds39927c-page 196 ? 2008-2011 microchip technology inc. register 26-5: fwdt: watchdog timer configuration register r/p-1 r/p-1 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 fwdten windis ? fwpsa wdtps3 wdtps2 wdtps1 wdtps0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 fwdten: watchdog timer enable bit 1 = wdt is enabled 0 = wdt is disabled (control is placed on the swdten bit) bit 6 windis: windowed watchdog timer disable bit 1 = standard wdt is selected; windowed wdt disabled 0 = windowed wdt is enabled bit 5 unimplemented: read as ? 0 ? bit 4 fwpsa: wdt prescaler bit 1 = wdt prescaler ratio of 1:128 0 = wdt prescaler ratio of 1:32 bit 3-0 wdtps<3:0>: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1
? 2008-2011 microchip technology inc. ds39927c-page 197 pic24f16ka102 family register 26-6: fpor: rese t configuration register r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 u-0 r/p-1 r/p-1 mclre ( 2 ) borv1 ( 3 ) borv0 ( 3 ) i2c1sel ( 1 ) pwrten ? boren1 boren0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mclre: mclr pin enable bit ( 2 ) 1 = mclr pin is enabled; ra5 input pin is disabled 0 = ra5 input pin is enabled; mclr is disabled bit 6-5 borv<1:0>: brown-out reset enable bits ( 3 ) 11 = brown-out reset is set to the lowest voltage 10 = brown-out reset 01 = brown-out reset is set to the highest voltage 00 = low-power brown-out reset occurs around 2.0v bit 4 i2c1sel: alternate i2c1 pin mapping bit ( 1 ) 0 = alternate location for scl1/sda1 pins 1 = default location for scl1/sda1 pins bit 3 pwrten: power-up timer enable bit 0 = pwrt is disabled 1 = pwrt is enabled bit 2 unimplemented: read as ? 0 ? bit 1-0 boren<1:0>: brown-out reset enable bits 11 = brown-out reset is enabled in hardware; sboren bit is disabled 10 = brown-out reset is enabled only while device is active and disabled in sleep; sboren bit is disabled 01 = brown-out reset is controlled with the sboren bit setting 00 = brown-out reset is disabled in hardware; sboren bit is disabled note 1: applies only to 28-pin devices. 2: the mclre fuse can only be changed when using the v pp -based icsp? mode entry. this prevents a user from accidentally locking out the device from the low-voltage test entry. 3: refer to section 29.0, electrical characteristics for the bor voltages.
pic24f16ka102 family ds39927c-page 198 ? 2008-2011 microchip technology inc. register 26-7: ficd: in-circuit debugger configuration register r/p-1 u-0 u-0 u-0 u-0 u-0 r/p-1 r/p-1 debug ? ? ? ? ? ficd1 ficd0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 debug : background debugger enable bit 1 = background debugger is disabled 0 = background debugger functions are enabled bit 6-2 unimplemented: read as ? 0 ? bit 1-0 ficd<1:0:> icd pin select bits 11 = pgc1/pgd1 are used for programming and debugging the device 10 = pgc2/pgd2 are used for programming and debugging the device 01 = pgc3/pgd3 are used for programming and debugging the device 00 = reserved; do not use
? 2008-2011 microchip technology inc. ds39927c-page 199 pic24f16ka102 family register 26-8: fds: deep sleep configuration register r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 dswdten dsboren rtcosc dswdtosc dswdtps3 dswdtps2 dswdtps1 dswdtps0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 dswdten: deep sleep watchdog timer enable bit 1 = dswdt is enabled 0 = dswdt is disabled bit 6 dsboren: deep sleep/low-power bor enable bit (does not affect operation in non deep sleep modes) 1 = deep sleep bor is enabled in deep sleep 0 = deep sleep bor is disabled in deep sleep bit 5 rtcosc: rtcc reference clock select bit 1 = rtcc uses sosc as a reference clock 0 = rtcc uses lprc as a reference clock bit 4 dswdtosc: dswdt reference clock select bit 1 = dswdt uses lprc as a reference clock 0 = dswdt uses sosc as a reference clock bit 3-0 dswdtps<3:0>: deep sleep watchdog timer postscale select bits the dswdt prescaler is 32; this creates an approximate base time unit of 1 ms. 1111 = 1:2,147,483,648 (25.7 days) nominal 1110 = 1:536,870,912 (6.4 days) nominal 1101 = 1:134,217,728 (38.5 hours) nominal 1100 = 1:33,554,432 (9.6 hours) nominal 1011 = 1:8,388,608 (2.4 hours) nominal 1010 = 1:2,097,152 (36 minutes) nominal 1001 = 1:524,288 (9 minutes) nominal 1000 = 1:131,072 (135 seconds) nominal 0111 = 1:32,768 (34 seconds) nominal 0110 = 1:8,192 (8.5 seconds) nominal 0101 = 1:2,048 (2.1 seconds) nominal 0100 = 1:512 (528 ms) nominal 0011 = 1:128 (132 ms) nominal 0010 = 1:32 (33 ms) nominal 0001 = 1:8 (8.3 ms) nominal 0000 = 1:2 (2.1 ms) nominal
pic24f16ka102 family ds39927c-page 200 ? 2008-2011 microchip technology inc. register 26-9: devid: device id register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 23 bit 16 rrrrrrrr famid7 famid6 famid5 famid4 famid3 famid2 famid1 famid0 bit 15 bit 8 rrrrrrrr dev7 dev6 dev5 dev4 dev3 dev2 dev1 dev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 23-16 unimplemented: read as ? 0 ? bit 15-8 famid<7:0>: device family identifier bits 00001011 = pic24f16ka102 family bit 7-0 dev<7:0>: individual device identifier bits 00000011 = pic24f16ka102 00001010 = pic24f08ka102 00000001 = pic24f16ka101 00001000 = pic24f08ka101 register 26-10: devrev: device revision register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 23 bit 16 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r r r r ? ? ? ? rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 23-4 unimplemented: read as ? 0 ? bit 3-0 rev<3:0>: minor revision identifier bits
? 2008-2011 microchip technology inc. ds39927c-page 201 pic24f16ka102 family 26.2 watchdog timer (wdt) for the pic24f16ka102 family of devices, the wdt is driven by the lprc oscillator. when the wdt is enabled, the clock source is also enabled. the nominal wdt clock source from lprc is 31 khz. this feeds a prescaler that can be configured for either 5-bit (divide-by-32) or 7-bit (divide-by-128) operation. the prescaler is set by the fwpsa configuration bit. with a 31 khz input, the prescaler yields a nominal wdt time-out period (t wdt ) of 1 ms in 5-bit mode or 4 ms in 7-bit mode. a variable postscaler divides down the wdt prescaler output and allows for a wide range of time-out periods. the postscaler is controlled by the configuration bits, wdtps<3:0> (fwdt<3:0>), which allow the selection of a total of 16 settings, from 1:1 to 1:32,768. using the prescaler and postscaler time-out periods, ranging from 1 ms to 131 seconds, can be achieved. the wdt, prescaler and postscaler are reset: ? on any device reset ? on the completion of a clock switch, whether invoked by software (i.e., setting the oswen bit after changing the nosc bits) or by hardware (i.e., fail-safe clock monitor) ? when a pwrsav instruction is executed (i.e., sleep or idle mode is entered) ? when the device exits sleep or idle mode to resume normal operation ?by a clrwdt instruction during normal execution if the wdt is enabled, it will continue to run during sleep or idle modes. when the wdt time-out occurs, the device will wake the device and code execution will continue from where the pwrsav instruction was executed. the corresponding sleep or idle bits (rcon<3:2>) will need to be cleared in software after the device wakes up. the wdt flag bit, wdto (rcon<4>), is not automatically cleared following a wdt time-out. to detect subsequent wdt events, the flag must be cleared in software. 26.2.1 windowed operation the watchdog timer has an optional fixed window mode of operation. in this windowed mode, clrwdt instructions can only reset the wdt during the last 1/4 of the programmed wdt period. a clrwdt instruc- tion executed before that window causes a wdt reset, similar to a wdt time-out. windowed wdt mode is enabled by programming the configuration bit, windis (fwdt<6>), to ? 0 ?. 26.2.2 control register the wdt is enabled or disabled by the fwdten configuration bit. when the fwdten configuration bit is set, the wdt is always enabled. the wdt can be optionally controlled in software when the fwdten configuration bit has been programmed to ? 0 ?. the wdt is enabled in software by setting the swdten control bit (rcon<5>). the swdten control bit is cleared on any device reset. the software wdt option allows the user to enable the wdt for critical code segments and disable the wdt during non-critical segments for maximum power savings. figure 26-1: wdt block diagram note: the clrwdt and pwrsav instructions clear the prescaler and postscaler counts when executed. lprc input wdt overflow wake from sleep 31 khz prescaler postscaler fwpsa swdten fwdten reset all device resets sleep or idle mode lprc control clrwdt instr. pwrsav instr. (5-bit/7-bit) 1:1 to 1:32.768 wdtps<3:0> 1 ms/4 ms exit sleep or idle mode wdt counter transition to new clock source
pic24f16ka102 family ds39927c-page 202 ? 2008-2011 microchip technology inc. 26.3 deep sleep watchdog timer (dswdt) in pic24f16ka102 family devices, in addition to the wdt module, a dswdt module is present which runs while the device is in deep sleep, if enabled. it is driven by either the sosc or lprc oscillator. the clock source is selected by the configuration bit, dswdtosc (fds<4>). the dswdt can be configured to generate a time-out at 2.1 ms to 25.7 days by selecting the respective postscaler. the postscaler can be selected by the configuration bits, dswdtps<3:0> (fds<3:0>). when the dswdt is enabled, the clock source is also enabled. dswdt is one of the sources that can wake-up the device from deep sleep mode. 26.4 program verification and code protection for all devices in the pic24f16ka102 family, code protection for the boot segment is controlled by the configuration bit, bss0, and the general segment by the configuration bit, gss0. these bits inhibit external reads and writes to the program memory space; this has no direct effect in normal execution mode. write protection is controlled by bit, bwrp, for the boot segment and bit, gwrp, for the general segment in the configuration word. when these bits are programmed to ? 0 ?, internal write and erase operations to program memory are blocked. 26.5 in-circuit serial programming pic24f16ka102 family microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock (pgcx) and data (pgdx), and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. 26.6 in-circuit debugger when mplab ? icd 2 is selected as a debugger, the in-circuit debugging functionality is enabled. this function allows simple debugging functions when used with mplab ide. debugging functionality is controlled through the emucx (emulation/debug clock) and emudx (emulation/debug data) pins. to use the in-circuit debugger function of the device, the design must implement icsp connections to mclr , v dd , v ss , pgcx, pgdx and the emudx/emucx pin pair. in addition, when the feature is enabled, some of the resources are not available for general use. these resources include the first 80 bytes of data ram and two i/o pins.
? 2008-2011 microchip technology inc. preliminary ds39927c-page 203 pic24f16ka102 family 27.0 development support the pic ? microcontrollers and dspic ? digital signal controllers are supported with a full range of software and hardware development tools: ? integrated development environment - mplab ? ide software ? compilers/assemblers/linkers - mplab c compiler for various device families - hi-tech c ? for various device families - mpasm tm assembler -mplink tm object linker/ mplib tm object librarian - mplab assembler/linker/librarian for various device families ? simulators - mplab sim software simulator ?emulators - mplab real ice? in-circuit emulator ? in-circuit debuggers - mplab icd 3 - pickit? 3 debug express ? device programmers - pickit? 2 programmer - mplab pm3 device programmer ? low-cost demonstration/development boards, evaluation kits, and starter kits 27.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16/32-bit microcontroller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - in-circuit emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as iar c compilers the mplab ide allows you to: ? edit your source files (either c or assembly) ? one-touch compile or assemble, and download to emulator and simulator tools (automatically updates all project information) ? debug using: - source files (c or assembly) - mixed c and assembly - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic24f16ka102 family ds39927c-page 204 preliminary ? 2008-2011 microchip technology inc. 27.2 mplab c compilers for various device families the mplab c compiler code development systems are complete ansi c compilers for microchip?s pic18, pic24 and pic32 families of microcontrollers and the dspic30 and dspic33 families of digital signal control- lers. these compilers provide powerful integration capabilities, superior code optimization and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 27.3 hi-tech c for various device families the hi-tech c compiler code development systems are complete ansi c compilers for microchip?s pic family of microcontrollers and the dspic family of digital signal controllers. these compilers provide powerful integration capabilities, omniscient code generation and ease of use. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. the compilers include a macro assembler, linker, pre- processor, and one-step driver, and can run on multiple platforms. 27.4 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for pic10/12/16/18 mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 27.5 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 27.6 mplab assembler, linker and librarian for various device families mplab assembler produces relocatable machine code from symbolic assembly language for pic24, pic32 and dspic devices. mplab c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire device instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility
? 2008-2011 microchip technology inc. preliminary ds39927c-page 205 pic24f16ka102 family 27.7 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c compilers, and the mpasm and mplab assemblers. the soft- ware simulator offers the flexibility to develop and debug code outside of the hardware laboratory envi- ronment, making it an excellent, economical software development tool. 27.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the emulator is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with in- circuit debugger systems (rj11) or with the new high- speed, noise tolerant, low-voltage differential signal (lvds) interconnection (cat5). the emulator is field upgradable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, run-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 27.9 mplab icd 3 in-circuit debugger system mplab icd 3 in-circuit debugger system is micro- chip's most cost effective high-speed hardware debugger/programmer for microchip flash digital sig- nal controller (dsc) and microcontroller (mcu) devices. it debugs and programs pic ? flash microcon- trollers and dspic ? dscs with the powerful, yet easy- to-use graphical user interface of mplab integrated development environment (ide). the mplab icd 3 in-circuit debugger probe is con- nected to the design engineer's pc using a high-speed usb 2.0 interface and is connected to the target with a connector compatible with the mplab icd 2 or mplab real ice systems (rj-11). mplab icd 3 supports all mplab icd 2 headers. 27.10 pickit 3 in-circuit debugger/ programmer and pickit 3 debug express the mplab pickit 3 allows debugging and program- ming of pic ? and dspic ? flash microcontrollers at a most affordable price point using the powerful graphical user interface of the mplab integrated development environment (ide). the mplab pickit 3 is connected to the design engineer's pc using a full speed usb interface and can be connected to the target via an microchip debug (rj-11) connector (compatible with mplab icd 3 and mplab real ice). the connector uses two device i/o pins and the reset line to imple- ment in-circuit debugging and in-circuit serial pro- gramming?. the pickit 3 debug express include the pickit 3, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software.
pic24f16ka102 family ds39927c-page 206 preliminary ? 2008-2011 microchip technology inc. 27.11 pickit 2 development programmer/debugger and pickit 2 debug express the pickit? 2 development programmer/debugger is a low-cost development tool with an easy to use inter- face for programming and debugging microchip?s flash families of microcontrollers. the full featured windows ? programming interface supports baseline (pic10f, pic12f5xx, pic16f5xx), midrange (pic12f6xx, pic16f), pic18f, pic24, dspic30, dspic33, and pic32 families of 8-bit, 16-bit, and 32-bit microcontrollers, and many microchip serial eeprom products. with microchip?s powerful mplab integrated development environment (ide) the pickit? 2 enables in-circuit debugging on most pic ? microcon- trollers. in-circuit-debugging runs, halts and single steps the program while the pic microcontroller is embedded in the application. when halted at a break- point, the file registers can be examined and modified. the pickit 2 debug express include the pickit 2, demo board and microcontroller, hookup cables and cdrom with user?s guide, lessons, tutorial, compiler and mplab ide software. 27.12 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an mmc card for file storage and data applications. 27.13 demonstration/development boards, evaluation kits, and starter kits a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. also available are starter kits that contain everything needed to experience the specified device. this usually includes a single application and debug capability, all on one board. check the microchip web page ( www.microchip.com ) for the complete list of demonstration, development and evaluation kits.
? 2008-2011 microchip technology inc. ds39927c-page 207 pic24f16ka102 family 28.0 instruction set summary the pic24f instruction set adds many enhancements to the previous pic ? mcu instruction sets, while maintaining an easy migration from previous pic mcu instruction sets. most instructions are a single program memory word. only three instructions require two program memory locations. each single-word instruction is a 24-bit word divided into an 8-bit opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? word or byte-oriented operations ? bit-oriented operations ? literal operations ? control operations table 28-1 lists the general symbols used in describing the instructions. the pic24f instruction set summary in tab l e 2 8- 2 lists all the instructions, along with the status flags affected by each instruction. most word or byte-oriented w register instructions (including barrel shift instructions) have three operands: ? the first source operand, which is typically a register ?wb? without any address modifier ? the second source operand, which is typically a register ?ws? with or without an address modifier ? the destination of the result, which is typically a register ?wd? with or without an address modifier however, word or byte-oriented file register instructions have two operands: ? the file register, specified by the value, ?f? ? the destination, which could either be the file register ?f? or the w0 register, which is denoted as ?wreg? most bit-oriented instructions (including simple rotate/shift instructions) have two operands: ? the w register (with or without an address modifier) or file register (specified by the value of ?ws? or ?f?) ? the bit in the w register or file register (specified by a literal value or indirectly by the contents of register ?wb?) the literal instructions that involve data movement may use some of the following operands: ? a literal value to be loaded into a w register or file register (specified by the value of ?k?) ? the w register or file register, where the literal value is to be loaded (specified by ?wb? or ?f?) however, literal instructions that involve arithmetic or logical operations use some of the following operands: ? the first source operand, which is a register ?wb? without any address modifier ? the second source operand, which is a literal value ? the destination of the result (only if not the same as the first source operand), which is typically a register ?wd? with or without an address modifier the control instructions may use some of the following operands: ? a program memory address ? the mode of the table read and table write instructions all instructions are a single word, except for certain double-word instructions, which were made double-word instructions so that all of the required information is available in these 48 bits. in the second word, the 8 msbs are ? 0 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . most single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter (pc) is changed as a result of the instruction. in these cases, the execution takes two instruction cycles, with the additional instruction cycle(s) executed as a nop . notable exceptions are the bra (unconditional/computed branch), indirect call/goto , all table reads and writes, and return/retfie instructions, which are single-word instructions but take two or three cycles. certain instructions that involve skipping over the subsequent instruction require either two or three cycles if the skip is performed, depending on whether the instruction being skipped is a single-word or two-word instruction. moreover, double-word moves require two cycles. the double-word instructions execute in two instruction cycles. note: this chapter is a brief summary of the pic24f instruction set architecture and is not intended to be a comprehensive reference source.
pic24f16ka102 family ds39927c-page 208 ? 2008-2011 microchip technology inc. table 28-1: symbols used in opcode descriptions field description #text means literal defined by ? text ? (text) means ?content of text ? [text] means ?the location addressed by text ? { } optional field or operation register bit field .b byte mode selection .d double-word mode selection .s shadow register select .w word mode selection (default) bit4 4-bit bit selection field (used in word addressed instructions) ?? {0...15} c, dc, n, ov, z mcu status bits: carry, digit carry, negative, overflow, sticky zero expr absolute address, label or expression (resolved by the linker) f file register address ?? {0000h...1fffh} lit1 1-bit unsigned literal ?? {0,1} lit4 4-bit unsigned literal ?? {0...15} lit5 5-bit unsigned literal ?? {0...31} lit8 8-bit unsigned literal ?? {0...255} lit10 10-bit unsigned literal ?? {0...255} for byte mode, {0:1023} for word mode lit14 14-bit unsigned literal ?? {0...16384} lit16 16-bit unsigned literal ?? {0...65535} lit23 23-bit unsigned literal ?? {0...8388608}; lsb must be ? 0 ? none field does not require an entry, may be blank pc program counter slit10 10-bit signed literal ?? {-512...511} slit16 16-bit signed literal ?? {-32768...32767} slit6 6-bit signed literal ?? {-16...16} wb base w register ?? {w0..w15} wd destination w register ?? { wd, [wd], [wd++], [wd--], [++wd], [--wd] } wdo destination w register ? { wnd, [wnd], [wnd++], [wnd--], [++wnd], [--wnd], [wnd+wb] } wm,wn dividend, divisor working r egister pair (direct addressing) wn one of 16 working registers ?? {w0..w15} wnd one of 16 destination working registers ?? {w0..w15} wns one of 16 source working registers ?? {w0..w15} wreg w0 (working register used in file register instructions) ws source w register ?? { ws, [ws], [ws++], [ws--], [++ws], [--ws] } wso source w register ?? { wns, [wns], [wns++], [wns--], [++wns], [--wns], [wns+wb] }
? 2008-2011 microchip technology inc. ds39927c-page 209 pic24f16ka102 family table 28-2: instruction set overview assembly mnemonic assembly syntax description # of words # of cycles status flags affected add add f f = f + wreg 1 1 c, dc, n, ov, z add f,wreg wreg = f + wreg 1 1 c, dc, n, ov, z add #lit10,wn wd = lit10 + wd 1 1 c, dc, n, ov, z add wb,ws,wd wd = wb + ws 1 1 c, dc, n, ov, z add wb,#lit5,wd wd = wb + lit5 1 1 c, dc, n, ov, z addc addc f f = f + wreg + (c) 1 1 c, dc, n, ov, z addc f,wreg wreg = f + wreg + (c) 1 1 c, dc, n, ov, z addc #lit10,wn wd = lit10 + wd + (c) 1 1 c, dc, n, ov, z addc wb,ws,wd wd = wb + ws + (c) 1 1 c, dc, n, ov, z addc wb,#lit5,wd wd = wb + lit5 + (c) 1 1 c, dc, n, ov, z and and f f = f .and. wreg 1 1 n, z and f,wreg wreg = f .and. wreg 1 1 n, z and #lit10,wn wd = lit10 .and. wd 1 1 n, z and wb,ws,wd wd = wb .and. ws 1 1 n, z and wb,#lit5,wd wd = wb .and. lit5 1 1 n, z asr asr f f = arithmetic right shift f 1 1 c, n, ov, z asr f,wreg wreg = arithmetic right shift f 1 1 c, n, ov, z asr ws,wd wd = arithmetic right shift ws 1 1 c, n, ov, z asr wb,wns,wnd wnd = arithmetic right shift wb by wns 1 1 n, z asr wb,#lit5,wnd wnd = arithmetic right shift wb by lit5 1 1 n, z bclr bclr f,#bit4 bit clear f 1 1 none bclr ws,#bit4 bit clear ws 1 1 none bra bra c,expr branch if carry 1 1 (2) none bra ge,expr branch if greater than or equal 1 1 (2) none bra geu,expr branch if unsigned greater than or equal 1 1 (2) none bra gt,expr branch if greater than 1 1 (2) none bra gtu,expr branch if unsigned greater than 1 1 (2) none bra le,expr branch if less than or equal 1 1 (2) none bra leu,expr branch if unsigned less than or equal 1 1 (2) none bra lt,expr branch if less than 1 1 (2) none bra ltu,expr branch if unsigned less than 1 1 (2) none bra n,expr branch if negative 1 1 (2) none bra nc,expr branch if not carry 1 1 (2) none bra nn,expr branch if not negative 1 1 (2) none bra nov,expr branch if not overflow 1 1 (2) none bra nz,expr branch if not zero 1 1 (2) none bra ov,expr branch if overflow 1 1 (2) none bra expr branch unconditionally 1 2 none bra z,expr branch if zero 1 1 (2) none bra wn computed branch 1 2 none bset bset f,#bit4 bit set f 1 1 none bset ws,#bit4 bit set ws 1 1 none bsw bsw.c ws,wb write c bit to ws 1 1 none bsw.z ws,wb write z bit to ws 1 1 none btg btg f,#bit4 bit toggle f 1 1 none btg ws,#bit4 bit toggle ws 1 1 none btsc btsc f,#bit4 bit test f, skip if clear 1 1 (2 or 3) none btsc ws,#bit4 bit test ws, skip if clear 1 1 (2 or 3) none
pic24f16ka102 family ds39927c-page 210 ? 2008-2011 microchip technology inc. btss btss f,#bit4 bit test f, skip if set 1 1 (2 or 3) none btss ws,#bit4 bit test ws, skip if set 1 1 (2 or 3) none btst btst f,#bit4 bit test f 1 1 z btst.c ws,#bit4 bit test ws to c 1 1 c btst.z ws,#bit4 bit test ws to z 1 1 z btst.c ws,wb bit test ws to c 1 1 c btst.z ws,wb bit test ws to z 1 1 z btsts btsts f,#bit4 bit test then set f 1 1 z btsts.c ws,#bit4 bit test ws to c, then set 1 1 c btsts.z ws,#bit4 bit test ws to z, then set 1 1 z call call lit23 call subroutine 2 2 none call wn call indirect subroutine 1 2 none clr clr f f = 0x0000 1 1 none clr wreg wreg = 0x0000 1 1 none clr ws ws = 0x0000 1 1 none clrwdt clrwdt clear watchdog timer 1 1 wdto, sleep com com f f = f 11n, z com f,wreg wreg = f 11n, z com ws,wd wd = ws 11n, z cp cp f compare f with wreg 1 1 c, dc, n, ov, z cp wb,#lit5 compare wb with lit5 1 1 c, dc, n, ov, z cp wb,ws compare wb with ws (wb ? ws) 1 1 c, dc, n, ov, z cp0 cp0 f compare f with 0x0000 1 1 c, dc, n, ov, z cp0 ws compare ws with 0x0000 1 1 c, dc, n, ov, z cpb cpb f compare f with wreg, with borrow 1 1 c, dc, n, ov, z cpb wb,#lit5 compare wb with lit5, with borrow 1 1 c, dc, n, ov, z cpb wb,ws compare wb with ws, with borrow (wb ? ws ? c ) 1 1 c, dc, n, ov, z cpseq cpseq wb,wn compare wb with wn, skip if = 1 1 (2 or 3) none cpsgt cpsgt wb,wn compare wb with wn, skip if > 1 1 (2 or 3) none cpslt cpslt wb,wn compare wb with wn, skip if < 1 1 (2 or 3) none cpsne cpsne wb,wn compare wb with wn, skip if ? 11 (2 or 3) none daw daw wn wn = decimal adjust wn 1 1 c dec dec f f = f ?1 1 1 c, dc, n, ov, z dec f,wreg wreg = f ?1 1 1 c, dc, n, ov, z dec ws,wd wd = ws ? 1 1 1 c, dc, n, ov, z dec2 dec2 f f = f ? 2 1 1 c, dc, n, ov, z dec2 f,wreg wreg = f ? 2 1 1 c, dc, n, ov, z dec2 ws,wd wd = ws ? 2 1 1 c, dc, n, ov, z disi disi #lit14 disable interrupts for k instruction cycles 1 1 none div div.sw wm,wn signed 16/16-bit integer divide 1 18 n, z, c, ov div.sd wm,wn signed 32/16-bit integer divide 1 18 n, z, c, ov div.uw wm,wn unsigned 16/16-bit integer divide 1 18 n, z, c, ov div.ud wm,wn unsigned 32/16-bit integer divide 1 18 n, z, c, ov exch exch wns,wnd swap wns with wnd 1 1 none ff1l ff1l ws,wnd find first one from left (msb) side 1 1 c ff1r ff1r ws,wnd find first one from right (lsb) side 1 1 c table 28-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
? 2008-2011 microchip technology inc. ds39927c-page 211 pic24f16ka102 family goto goto expr go to address 2 2 none goto wn go to indirect 1 2 none inc inc f f = f + 1 1 1 c, dc, n, ov, z inc f,wreg wreg = f + 1 1 1 c, dc, n, ov, z inc ws,wd wd = ws + 1 1 1 c, dc, n, ov, z inc2 inc2 f f = f + 2 1 1 c, dc, n, ov, z inc2 f,wreg wreg = f + 2 1 1 c, dc, n, ov, z inc2 ws,wd wd = ws + 2 1 1 c, dc, n, ov, z ior ior f f = f .ior. wreg 1 1 n, z ior f,wreg wreg = f .ior. wreg 1 1 n, z ior #lit10,wn wd = lit10 .ior. wd 1 1 n, z ior wb,ws,wd wd = wb .ior. ws 1 1 n, z ior wb,#lit5,wd wd = wb .ior. lit5 1 1 n, z lnk lnk #lit14 link frame pointer 1 1 none lsr lsr f f = logical right shift f 1 1 c, n, ov, z lsr f,wreg wreg = logical right shift f 1 1 c, n, ov, z lsr ws,wd wd = logical right shift ws 1 1 c, n, ov, z lsr wb,wns,wnd wnd = logical right shift wb by wns 1 1 n, z lsr wb,#lit5,wnd wnd = logical right shift wb by lit5 1 1 n, z mov mov f,wn move f to wn 1 1 none mov [wns+slit10],wnd move [wns+slit10] to wnd 1 1 none mov f move f to f 1 1 n, z mov f,wreg move f to wreg 1 1 n, z mov #lit16,wn move 16-bit literal to wn 1 1 none mov.b #lit8,wn move 8-bit literal to wn 1 1 none mov wn,f move wn to f 1 1 none mov wns,[wns+slit10] move wns to [wns+slit10] 1 1 none mov wso,wdo move ws to wd 1 1 none mov wreg,f move wreg to f 1 1 n, z mov.d wns,wd move double from w(ns):w(ns+1) to wd 1 2 none mov.d ws,wnd move double from ws to w(nd+1):w(nd) 1 2 none mul mul.ss wb,ws,wnd {wnd+1, wnd} = signed(wb) * signed(ws) 1 1 none mul.su wb,ws,wnd {wnd+1, wnd} = signed(wb) * unsigned(ws) 1 1 none mul.us wb,ws,wnd {wnd+1, wnd} = unsigned(wb) * signed(ws) 1 1 none mul.uu wb,ws,wnd {wnd+1, wnd} = unsigned(wb) * unsigned(ws) 1 1 none mul.su wb,#lit5,wnd {wnd+1, wnd} = signed(wb) * unsigned(lit5) 1 1 none mul.uu wb,#lit5,wnd {wnd+1, wnd} = unsigned(wb) * unsigned(lit5) 1 1 none mul f w3:w2 = f * wreg 1 1 none neg neg f f = f + 1 1 1 c, dc, n, ov, z neg f,wreg wreg = f + 1 1 1 c, dc, n, ov, z neg ws,wd wd = ws + 1 1 1 c, dc, n, ov, z nop nop no operation 1 1 none nopr no operation 1 1 none pop pop f pop f from top-of-stack (tos) 1 1 none pop wdo pop from top-of-stack (tos) to wdo 1 1 none pop.d wnd pop from top-of-stack (tos) to w(nd):w(nd+1) 1 2 none pop.s pop shadow registers 1 1 all push push f push f to top-of-stack (tos) 1 1 none push wso push wso to top-of-stack (tos) 1 1 none push.d wns push w(ns):w(ns+1) to top-of-stack (tos) 1 2 none push.s push shadow registers 1 1 none table 28-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
pic24f16ka102 family ds39927c-page 212 ? 2008-2011 microchip technology inc. pwrsav pwrsav #lit1 go into sleep or idle mode 1 1 wdto, sleep rcall rcall expr relative call 1 2 none rcall wn computed call 1 2 none repeat repeat #lit14 repeat next instruction lit14 + 1 times 1 1 none repeat wn repeat next instruction (wn) + 1 times 1 1 none reset reset software device reset 1 1 none retfie retfie return from interrupt 1 3 (2) none retlw retlw #lit10,wn return with literal in wn 1 3 (2) none return return return from subroutine 1 3 (2) none rlc rlc f f = rotate left through carry f 1 1 c, n, z rlc f,wreg wreg = rotate left through carry f 1 1 c, n, z rlc ws,wd wd = rotate left through carry ws 1 1 c, n, z rlnc rlnc f f = rotate left (no carry) f 1 1 n, z rlnc f,wreg wreg = rotate left (no carry) f 1 1 n, z rlnc ws,wd wd = rotate left (no carry) ws 1 1 n, z rrc rrc f f = rotate right through carry f 1 1 c, n, z rrc f,wreg wreg = rotate right through carry f 1 1 c, n, z rrc ws,wd wd = rotate right through carry ws 1 1 c, n, z rrnc rrnc f f = rotate right (no carry) f 1 1 n, z rrnc f,wreg wreg = rotate right (no carry) f 1 1 n, z rrnc ws,wd wd = rotate right (no carry) ws 1 1 n, z se se ws,wnd wnd = sign-extended ws 1 1 c, n, z setm setm f f = ffffh 1 1 none setm wreg wreg = ffffh 1 1 none setm ws ws = ffffh 1 1 none sl sl f f = left shift f 1 1 c, n, ov, z sl f,wreg wreg = left shift f 1 1 c, n, ov, z sl ws,wd wd = left shift ws 1 1 c, n, ov, z sl wb,wns,wnd wnd = left shift wb by wns 1 1 n, z sl wb,#lit5,wnd wnd = left shift wb by lit5 1 1 n, z sub sub f f = f ? wreg 1 1 c, dc, n, ov, z sub f,wreg wreg = f ? wreg 1 1 c, dc, n, ov, z sub #lit10,wn wn = wn ? lit10 1 1 c, dc, n, ov, z sub wb,ws,wd wd = wb ? ws 1 1 c, dc, n, ov, z sub wb,#lit5,wd wd = wb ? lit5 1 1 c, dc, n, ov, z subb subb f f = f ? wreg ? (c ) 1 1 c, dc, n, ov, z subb f,wreg wreg = f ? wreg ? (c ) 1 1 c, dc, n, ov, z subb #lit10,wn wn = wn ? lit10 ? (c ) 1 1 c, dc, n, ov, z subb wb,ws,wd wd = wb ? ws ? (c ) 1 1 c, dc, n, ov, z subb wb,#lit5,wd wd = wb ? lit5 ? (c ) 1 1 c, dc, n, ov, z subr subr f f = wreg ? f 1 1 c, dc, n, ov, z subr f,wreg wreg = wreg ? f 1 1 c, dc, n, ov, z subr wb,ws,wd wd = ws ? wb 1 1 c, dc, n, ov, z subr wb,#lit5,wd wd = lit5 ? wb 1 1 c, dc, n, ov, z subbr subbr f f = wreg ? f ? (c ) 1 1 c, dc, n, ov, z subbr f,wreg wreg = wreg ? f ? (c ) 1 1 c, dc, n, ov, z subbr wb,ws,wd wd = ws ? wb ? (c ) 1 1 c, dc, n, ov, z subbr wb,#lit5,wd wd = lit5 ? wb ? (c ) 1 1 c, dc, n, ov, z swap swap.b wn wn = nibble swap wn 1 1 none swap wn wn = byte swap wn 1 1 none tblrdh tblrdh ws,wd read prog<23:16> to wd<7:0> 1 2 none table 28-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
? 2008-2011 microchip technology inc. ds39927c-page 213 pic24f16ka102 family tblrdl tblrdl ws,wd read prog<15:0> to wd 1 2 none tblwth tblwth ws,wd write ws<7:0> to prog<23:16> 1 2 none tblwtl tblwtl ws,wd write ws to prog<15:0> 1 2 none ulnk ulnk unlink frame pointer 1 1 none xor xor f f = f .xor. wreg 1 1 n, z xor f,wreg wreg = f .xor. wreg 1 1 n, z xor #lit10,wn wd = lit10 .xor. wd 1 1 n, z xor wb,ws,wd wd = wb .xor. ws 1 1 n, z xor wb,#lit5,wd wd = wb .xor. lit5 1 1 n, z ze ze ws,wnd wnd = zero-extend ws 1 1 c, z, n table 28-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
pic24f16ka102 family ds39927c-page 214 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 215 pic24f16ka102 family 29.0 electrical characteristics this section provides an overview of the pic24f16ka102 family electrical characteristics. additional information will be provided in future revisions of this document as it becomes available. absolute maximum ratings for the pic24f16ka102 family are listed below. exposure to these maximum rating conditions for extended periods may affect device reliability. functional operation of the device at these, or any other conditions above the parameters indicated in the operation listings of this specification, is not implied. absolute maximum ratings ( ? ) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +175c voltage on v dd with respect to v ss ......................................................................................................... -0.3v to +5.0v voltage on any combined analog and digital pin, with respect to v ss ........................................... -0.3v to (v dd + 0.3v) voltage on any digital only pin with respect to v ss ....................................................................... -0.3v to (v dd + 0.3v) voltage on mclr /v pp pin with respect to v ss ......................................................................................... -0.3v to +9.0v maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ( 1 ) ..........................................................................................................................250 m a maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by all ports .............................................................................................. .........................200 ma maximum current sourced by all ports ( 1 ) ..............................................................................................................200 ma note 1: maximum allowable current is a function of device maximum power dissipation (see tab l e 2 9- 1 ). ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic24f16ka102 family ds39927c-page 216 ? 2008-2011 microchip technology inc. 29.1 dc characteristics figure 29-1: pic24f16ka102 family voltage-frequency graph (industrial) figure 29-2: pic24f16ka102 fami ly voltage-frequency graph (industrial, extended) frequency (mhz) voltage (v dd ) 1.80v 32 mhz 3.60v 3.00v 3.60v 8 mhz note: for industrial temperatures, for frequencies between 8 mhz and 32 mhz, f max = (20 mhz/v) * (v dd ? 1.8v) + 8 mhz. 0 24 mhz 16 mhz 0 3.00v frequency (mhz) voltage (v dd ) 1.80v 32 mhz 3.60v 3.00v 3.60v 8 mhz 3.00v note: for extended temperatures, for frequencies between 8 mhz and 24 mhz, f max = (13.33 mhz/v) * (v dd ? 1.8v) + 8 mhz. 0 24 mhz 16 mhz 0
? 2008-2011 microchip technology inc. ds39927c-page 217 pic24f16ka102 family table 29-1: thermal operating conditions rating symbol min typ max unit operating junction temperature range t j -40 ? +175 c operating ambient temperature range t a -40 ? +125 c power dissipation: internal chip power dissipation: p int = v dd x (i dd ? ? i oh ) p d p int + p i / o w i/o pin power dissipation: p i / o = ? ({v dd ? v oh } x i oh ) + ? (v ol x i ol ) maximum allowed power dissipation p dmax (t j ? t a )/ ? ja w table 29-2: thermal packaging characteristics characteristic symbol typ max unit notes package thermal resistance, 20-pin pdip ? ja 62.4 ? c/w 1 package thermal resistance, 28-pin spdip ? ja 60 ? c/w 1 package thermal resistance, 20-pin ssop ? ja 108 ? c/w 1 package thermal resistance, 28-pin ssop ? ja 71 ? c/w 1 package thermal resistance, 20-pin soic ? ja 75 ? c/w 1 package thermal resistance, 28-pin soic ? ja 80.2 ? c/w 1 package thermal resistance, 20-pin qfn ? ja 43 ? c/w 1 package thermal resistance, 28-pin qfn ? ja 32 ? c/w 1 note 1: junction to ambient thermal resistance, theta- ja ( ? ja ) numbers are achieved by package simulations.
pic24f16ka102 family ds39927c-page 218 ? 2008-2011 microchip technology inc. table 29-4: high/low?voltage detect characteristics table 29-3: dc characteristics: temperature and voltage specifications dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ ( 1 ) max units conditions dc10 v dd supply voltage 1.8 ? 3.6 v dc12 v dr ram data retention voltage ( 2 ) 1.5 ? ? v dc16 v por v dd start voltage to ensure internal power-on reset signal v ss ?0.7v dc17 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms 0-3.3v in 0.1s 0-2.5v in 60 ms note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: this is the limit to which v dd can be lowered without losing ram data. standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ max units conditions dc18 v hlvd hlvd voltage on v dd transition hlvdl<3:0> = 0000 ?1.851.94v hlvdl<3:0> = 0001 1.81 1.90 2.00 v hlvdl<3:0> = 0010 1.85 1.95 2.05 v hlvdl<3:0> = 0011 1.90 2.00 2.10 v hlvdl<3:0> = 0100 1.95 2.05 2.15 v hlvdl<3:0> = 0101 2.06 2.17 2.28 v hlvdl<3:0> = 0110 2.12 2.23 2.34 v hlvdl<3:0> = 0111 2.24 2.36 2.48 v hlvdl<3:0> = 1000 2.31 2.43 2.55 v hlvdl<3:0> = 1001 2.47 2.60 2.73 v hlvdl<3:0> = 1010 2.64 2.78 2.92 v hlvdl<3:0> = 1011 2.74 2.88 3.02 v hlvdl<3:0> = 1100 2.85 3.00 3.15 v hlvdl<3:0> = 1101 2.96 3.12 3.28 v hlvdl<3:0> = 1110 3.22 3.39 3.56 v
? 2008-2011 microchip technology inc. ds39927c-page 219 pic24f16ka102 family figure 29-3: brown-out reset characteristics table 29-5: bor trip points standard operating conditions (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ max units conditions dc19 v bor bor voltage on v dd transition bor = 00 ? ? ? ? lpbor ( 1 ) bor = 01 2.92 3 3.08 v bor = 10 2.63 2.7 2.77 v bor = 11 1.75 1.82 1.85 v dc14 v bhys bor hysteresis ? 5 ? mv note 1: lpbor re-arms the por circuit, but does not cause a bor. lpbor can be used to ensure a por after the sup- ply voltage rises to a safe operating level. it does not stop code execution after the supply voltage falls below a chosen trip point. bo10 reset (due to bor) v ddcore (device in brown-out reset) (device not in brown-out reset) t vreg + t rst bo15 sy25
pic24f16ka102 family ds39927c-page 220 ? 2008-2011 microchip technology inc. table 29-6: dc characteristics: operating current (i dd ) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended parameter no. typical ( 1 ) max units conditions i dd current ( 2 ) dc20 195 330 ? a -40c 1.8v 0.5 mips, f osc = 1 mhz ds20a 330 +25c dc20b 330 +60c dc20c 330 +85c dc20d 500 +125c dc20e 365 590 ? a -40c 3.3v dc20f 590 +25c dc20g 645 +60c dc20h 720 +85c dc20i 800 +125c dc22 363 600 ? a -40c 1.8v 1 mips, f osc = 2 mhz dc22a 600 +25c dc22b 600 +60c dc22c 600 +85c dc22d 800 +125c dc22e 695 1100 ? a -40c 3.3v dc22f 1100 +25c dc22g 1100 +60c dc22h 1100 +85c dc22i 1500 +125c dc23 11 18 ma -40c 3.3v 16 mips, f osc = 32 mhz dc23a 18 +25c dc23b 18 +60c dc23c 18 +85c dc23d 18 +125c dc27 2.25 3.40 ma -40c 2.5v frc (4 mips), f osc = 8 mhz dc27a 3.40 +25c dc27b 3.40 +60c dc27c 3.40 +85c dc27d 3.40 +125c dc27e 3.05 4.60 ma -40c 3.3v dc27f 4.60 +25c dc27g 4.60 +60c dc27h 4.60 +85c dc27i 5.40 +125c note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? ec mode with clock input driven with a square wave rail-to-rail ? i/os are configured as outputs, driven low ? mclr ? v dd ? wdt fscm is disabled ? sram, program and data memory are active ? all pmd bits are set except for modules being measured
? 2008-2011 microchip technology inc. ds39927c-page 221 pic24f16ka102 family dc31 8 28 ? a -40c 1.8v lprc (31 khz) dc31a 28 +25c dc31b 28 +60c dc31c 28 +85c dc31d 15 55 ? a -40c 3.3v dc31e 55 +25c dc31f 55 +60c dc31g 55 +85c dc31h 250 +125c table 29-6: dc characteristics: operating current (i dd ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended parameter no. typical ( 1 ) max units conditions i dd current ( 2 ) note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? ec mode with clock input driven with a square wave rail-to-rail ? i/os are configured as outputs, driven low ? mclr ? v dd ? wdt fscm is disabled ? sram, program and data memory are active ? all pmd bits are set except for modules being measured
pic24f16ka102 family ds39927c-page 222 ? 2008-2011 microchip technology inc. table 29-7: dc characteristics: idle current (i idle ) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. typical ( 1 ) max units conditions idle current (i idle ): core off, clock on base current, pmd bits are set ( 2 ) dc40 48 100 ? a -40c 1.8v 0.5 mips, f osc = 1 mhz dc40a 100 +25c dc40b 100 +60c dc40c 100 +85c dc40d 100 +125c dc40e 106 215 ? a -40c 3.3v dc40f 215 +25c dc40g 215 +60c dc40h 215 +85c dc40i 450 +125c dc42 94 200 ? a -40c 1.8v 1 mips, f osc = 2 mhz dc42a 200 +25c dc42b 200 +60c dc42c 200 +85c dc42d 300 +125c dc42e 160 395 ? a -40c 3.3v dc42f 395 +25c dc42g 395 +60c dc42h 395 +85c dc42i 600 +125c dc43 3.1 6.0 ma -40c 3.3v 16 mips, f osc = 32 mhz dc43a 6.0 +25c dc43b 6.0 +60c dc43c 6.0 +85c dc43d 6.0 +125c dc44 0.56 0.74 ma -40c 1.8v frc (4 mips), f osc = 8 mhz dc44a 0.74 +25c dc44b 0.74 +60c dc44c 0.74 +85c dc44d 0.74 +125c dc44e 0.95 1.50 ma -40c 3.3v dc44f 1.50 +25c dc44g 1.50 +60c dc44h 1.50 +85c dc44i 1.50 +125c note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? core is off ? ec mode with the clock input driven with a square wave rail-to-rail ? i/os are configured as outputs, driven low ? mclr ? v dd ? wdt fscm are disabled ? sram, program and data memory are active ? all pmd bits are set except for the modules being measured
? 2008-2011 microchip technology inc. ds39927c-page 223 pic24f16ka102 family dc50 2 18 ? a -40c 1.8v lprc (31 khz) dc50a 18 +25c dc50b 18 +60c dc50c 18 +85c dc50d 4 40 -40c 3.3v dc50e 40 +25c dc50f 40 +60c dc50g 40 +85c dc50h 60 +125c table 29-7: dc characteristics: idle current (i idle ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. typical ( 1 ) max units conditions idle current (i idle ): core off, clock on base current, pmd bits are set ( 2 ) note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? core is off ? ec mode with the clock input driven with a square wave rail-to-rail ? i/os are configured as outputs, driven low ? mclr ? v dd ? wdt fscm are disabled ? sram, program and data memory are active ? all pmd bits are set except for the modules being measured
pic24f16ka102 family ds39927c-page 224 ? 2008-2011 microchip technology inc. table 29-8: dc characteristics: power-down current (i pd ) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended parameter no. typical ( 1 ) max units conditions power-down current (i pd ): pmd bits are set, pmslp bit is ? 0 ? ( 2 ) dc60 0.025 0.200 ? a -40c 1.8v base power-down current (sleep) ( 3 ) dc60a 0.200 +25c dc60b 0.870 +60c dc60c 1.350 +85c dc60d 10.00 +125c dc60e 0.105 0.540 ? a -40c 3.3v dc60f 0.540 +25c dc60g 1.680 +60c dc60h 2.450 +85c dc60i 11.00 +125c dc70 0.020 0.150 ? a -40c 1.8v base deep sleep current dc70a 0.150 +25c dc70b 0.430 +60c dc70c 0.630 +85c dc70d 3.00 +125c dc70e 0.035 0.300 ? a -40c 3.3v dc70f 0.300 +25c dc70g 0.700 +60c dc70h 0.980 +85c dc70i 5.00 +125c dc61 0.55 0.65 ? a -40c 1.8v watchdog timer current (wdt) ( 3 , 4 ) dc61a 0.65 +25c dc61b 0.65 +60c dc61c 0.65 +85c dc61d 1.20 +125c dc61e 0.87 0.95 ? a -40c 3.3v dc61f 0.95 +25c dc61g 0.95 +60c dc61h 0.95 +85c dc61i 1.50 +125c note 1: data in the ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: base i pd is measured with all peripherals and clocks shut down. all i/os are configured as outputs and set low. wdt, etc., are all switched off. 3: the ? current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 4: current applies to sleep only. 5: current applies to sleep and deep sleep. 6: current applies to deep sleep only.
? 2008-2011 microchip technology inc. ds39927c-page 225 pic24f16ka102 family dc62 0.450 0.650 ? a -40c 1.8v timer1 w/32 khz crystal: t132 (sosc ? lp) ( 3 ) dc62a 0.650 +25c dc62b 0.650 +60c dc62c 0.650 +85c dc62d ? +125c dc62e 0.730 0.980 ? a -40c 3.3v dc62f 0.980 +25c dc62g 0.980 +60c dc62h 0.980 +85c dc62i ? +125c dc64 5.5 7.10 ? a -40c 1.8v hlvd ( 3 , 4 ) dc64a 7.10 +25c dc64b 7.80 +60c dc64c 8.30 +85c dc64d 10.00 +125c dc64e 6.2 7.10 ? a -40c 3.3v dc64f 7.10 +25c dc64g 7.80 +60c dc64h 8.30 +85c dc64i 9.00 +125c dc63 4.5 6.60 ? a -40c 3.3v bor ( 3 , 4 ) dc63a 6.60 +25c dc63b 6.60 +60c dc63c 6.60 +85c dc63d 9.00 +125c dc62 0.49 0.65 ? a -40c 1.8v rtcc ( 3 , 5 ) dc62a 0.65 +25c dc62b 0.65 +60c dc62c 0.65 +85c dc62d 0.98 +125c dc62e 0.80 0.98 ? a -40c 3.3v dc62f 0.98 +25c dc62g 0.98 +60c dc62h 0.98 +85c dc62i 0.98 +125c table 29-8: dc characteristics: power-down current (i pd ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended parameter no. typical ( 1 ) max units conditions power-down current (i pd ): pmd bits are set, pmslp bit is ? 0 ? ( 2 ) note 1: data in the ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: base i pd is measured with all peripherals and clocks shut down. all i/os are configured as outputs and set low. wdt, etc., are all switched off. 3: the ? current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 4: current applies to sleep only. 5: current applies to sleep and deep sleep. 6: current applies to deep sleep only.
pic24f16ka102 family ds39927c-page 226 ? 2008-2011 microchip technology inc. dc70 0.045 0.200 ? a -40c 1.8v lpbor ( 3 , 4 ) dc70a 0.200 +25c dc70b 0.200 +60c dc70c 0.200 +85c dc70d 1.45 +125c dc70e 0.095 0.200 ? a -40c 3.3v dc70f 0.200 +25c dc70g 0.200 +60c dc70h 0.200 +85c dc70i 1.55 +125c dc71 0.35 0.55 ? a -40c 1.8v deep sleep watchdog timer: dswdt (sosc ? lp) ( 6 ) dc71a 0.55 +25c dc71b 0.55 +60c dc71c 0.55 +85c dc71d 1.70 +125c dc71e 0.55 0.75 ? a -40c 3.3v dc71f 0.75 +25c dc71g 0.75 +60c dc71h 0.75 +85c dc71i 2.10 +125c dc72 0.005 0.200 ? a -40c 1.8v deep sleep bor (dsbor) ( 6 ) dc72a 0.200 +25c dc72b 0.200 +60c dc72c 0.200 +85c dc72d 0.200 +125c dc72e 0.010 0.200 ? a -40c 3.3v dc72f 0.200 +25c dc72g 0.200 +60c dc72h 0.200 +85c dc72i 0.200 +125c table 29-8: dc characteristics: power-down current (i pd ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended parameter no. typical ( 1 ) max units conditions power-down current (i pd ): pmd bits are set, pmslp bit is ? 0 ? ( 2 ) note 1: data in the ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: base i pd is measured with all peripherals and clocks shut down. all i/os are configured as outputs and set low. wdt, etc., are all switched off. 3: the ? current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 4: current applies to sleep only. 5: current applies to sleep and deep sleep. 6: current applies to deep sleep only.
? 2008-2011 microchip technology inc. ds39927c-page 227 pic24f16ka102 family table 29-9: dc characteristics: i/o pin input specifications dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions v il input low voltage ( 4 ) ???? di10 i/o pins v ss ? 0.2 v dd v di15 mclr v ss ? 0.2 v dd v di16 osci (xt mode) v ss ? 0.2 v dd v di17 osci (hs mode) v ss ? 0.2 v dd v di18 i/o pins with i 2 c? buffer v ss ? 0.3 v dd v smbus disabled di19 i/o pins with smbus buffer v ss ? 0.8 v smbus enabled v ih ( 5 ) input high voltage ( 4 ) ???? di20 i/o pins: with analog functions digital only 0.8 v dd 0.8 v dd ? ? v dd v dd v v di25 mclr 0.8 v dd ?v dd v di26 osci (xt mode) 0.7 v dd ?v dd v di27 osci (hs mode) 0.7 v dd ?v dd v di28 i/o pins with i 2 c buffer: with analog functions digital only 0.7 v dd 0.7 v dd ? ? v dd v dd v v di29 i/o pins with smbus 2.1 ? v dd v2.5v ? v pin ? v dd di30 i cnpu cnx pull-up current 50 250 500 ? av dd = 3.3v, v pin = v ss i il input leakage current ( 2 , 3 ) di50 i/o ports ? 0.050 0.100 ? av ss ? v pin ? v dd , pin at high-impedance di51 v ref +, v ref -, an0, an1 ? 0.300 0.500 ? av ss ? v pin ? v dd , pin at high-impedance di55 mclr ??5.0 ? av ss ?? v pin ?? v dd di56 osci ? ? 5.0 ? av ss ?? v pin ?? v dd , xt and hs modes note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: refer to ta b l e 1 - 2 for i/o pin buffer types. 5: v ih requirements are met when internal pull-ups are enabled.
pic24f16ka102 family ds39927c-page 228 ? 2008-2011 microchip technology inc. table 29-10: dc characteristics: i/o pin output specifications dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions v ol output low voltage do10 all i/o pins ? ? 0.4 v i ol = 4.0 ma, v dd = 3.6v ??0.4vi ol = 3.5 ma, v dd = 2.0v do16 osc2/clko ? ? 0.4 v i ol = 8.0 ma, v dd = 3.6v ??0.4vi ol = 4.5 ma, v dd = 1.8v v oh output high voltage do20 all i/o pins 3 ? ? v i oh = -3.0 ma, v dd = 3.6v 1.8 ? ? v i oh = -1.0 ma, v dd = 2.0v do26 osc2/clko 3 ? ? v i oh = -2.5 ma, v dd = 3.6v 1.8 ? ? v i oh = -1.0 ma, v dd = 2.0v note 1: data in ?typ? column is at 25c unless otherwise stated. parameters are for design guidance only and are not tested.
? 2008-2011 microchip technology inc. ds39927c-page 229 pic24f16ka102 family table 29-11: dc characteristics: program memory dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions program flash memory d130 e p cell endurance 10,000 ( 2 ) ??e/w d131 v pr v dd for read v min ?3.6vv min = minimum operating voltage d133a t iw self-timed write cycle time ? 2 ? ms d134 t retd characteristic retention 40 ? ? year provided no other specifications are violated d135 i ddp supply current during programming ?10?ma note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. 2: self-write and block erase. table 29-12: dc characteristics: data eeprom memory dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions data eeprom memory d140 e pd cell endurance 100,000 ? ? e/w d141 v prd v dd for read v min ?3.6vv min = minimum operating voltage d143a t iwd self-timed write cycle time ?4 ?ms d143b t ref number of total write/erase cycles before refresh ? 10m ? e/w d144 t retdd characteristic retention 40 ? ? year provided no other specifications are violated d145 i ddpd supply current during programming ?7 ?ma note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated.
pic24f16ka102 family ds39927c-page 230 ? 2008-2011 microchip technology inc. table 29-13: comparat or dc specifications table 29-14: comparator voltag e reference dc specifications table 29-15: internal voltage references operating conditions: 2.0v < v dd < 3.6v operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ max units comments d300 v ioff input offset voltage * ?20 40mv d301 v icm input common mode voltage * 0?v dd v d302 cmrr common mode rejection ratio * 55 ? ? db * parameters are characterized but not tested. operating conditions: 2.0v < v dd < 3.6v operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ max units comments vrd310 cv res resolution v dd /24 ? v dd /32 lsb vrd311 cvr aa absolute accuracy ? ? av dd ? 1.5 lsb vrd312 cvr ur unit resistor value (r) ? 2k ? ? operating conditions: 2.0v < v dd < 3.6v operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ max units comments v bg internal band gap reference 1.14 1.2 1.26 v t irvst internal reference stabilization time ? 200 250 ? s table 29-16: ctmu current source specifications dc characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions i out 1 ctmu current source, base range ? 550 ? na ctmuicon<1:0> = 01 i out 2 ctmu current source, 10x range ?5.5? ? a ctmuicon<1:0> = 10 i out 3 ctmu current source, 100x range ?55? ? a ctmuicon<1:0> = 11 note 1: nominal value at the center point of the current trim range (ctmuicon<7:2> = 000000 ).
? 2008-2011 microchip technology inc. ds39927c-page 231 pic24f16ka102 family 29.2 ac characteristics and timing parameters the information contained in this section defines the pic24f16ka102 family ac characteristics and timing parameters. table 29-17: temperature and vo ltage specifications ? ac figure 29-4: load conditions for device timing specifications table 29-18: capacitiv e loading requirements on output pins ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended operating voltage v dd range as described in section 29.1 ?dc characteristics? . param no. symbol characteristic min typ ( 1 ) max units conditions do50 c osc 2 osco/clko pin ? ? 15 pf in xt and hs modes when external clock is used to drive osci do56 c io all i/o pins and osco ? ? 50 pf ec mode do58 c b sclx, sdax ? ? 400 pf in i 2 c? mode note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. v dd /2 c l r l pin pin v ss v ss c l r l = 464 ? c l = 50 pf for all pins except osco 15 pf for osco output load condition 1 ? for all pins except osco load condition 2 ? for osco
pic24f16ka102 family ds39927c-page 232 ? 2008-2011 microchip technology inc. figure 29-5: external clock timing osci clko q4 q1 q2 q3 q4 q1 os20 os25 os30 os30 os40 os41 os31 os31 q1 q2 q3 q4 q2 q3 table 29-19: external clo ck timing requirements ac characteristics standard operating conditions: 1.8 to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions os10 f osc external clki frequency (external clocks allowed only in ec mode) ( 2 ) dc 4 ? ? 32 8 mhz mhz ec ecpll oscillator frequency ( 2 ) 0.2 4 4 31 ? ? ? ? 4 25 8 33 mhz mhz mhz khz xt hs hspll sosc os20 t osc t osc = 1/f osc ? ? ? ? see parameter os10 for f osc value os25 t cy instruction cycle time ( 3 ) 62.5 ? dc ns os30 tosl, to s h external clock in (osci) high or low time 0.45 x t osc ??nsec os31 tosr, to s f external clock in (osci) rise or fall time ??20nsec os40 tckr clko rise time ( 4 ) ?610ns os41 tckf clko fall time ( 4 ) ?610ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: refer to figure 29-1 for the minimum voltage at a given frequency. 3: instruction cycle period (t cy ) equals two times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osci/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. 4: measurements are taken in ec mode. the clko signal is measured on the osco pin. clko is low for the q1-q2 period (1/2 t cy ) and high for the q3-q4 period (1/2 t cy ).
? 2008-2011 microchip technology inc. ds39927c-page 233 pic24f16ka102 family table 29-20: pll clock ti ming specifications (v dd = 1.8v to 3.6v) ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic ( 1 ) min typ ( 2 ) max units conditions os50 f plli pll input frequency range 4 ? 8 mhz ecpll, hspll modes, -40c ? t a ? +85c os51 f sys pll output frequency range 16 ? 32 mhz -40c ? t a ? +85c os52 t lock pll start-up time (lock time) ?1 2ms os53 d clk clko stability (jitter) -2 1 2 % measured over a 100 ms period note 1: these parameters are characterized but not tested in manufacturing. 2: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. table 29-21: ac characteristics: internal rc accuracy ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. characteristic min typ max units conditions internal frc accuracy @ 8 mhz ( 1 ) f20 frc -1 ? +1 % +25c 3.0v ? v dd ? 3.6v -3 ? +3 % -40c ? t a ?? +85c -5 ? +5 % -40c ? t a ?? +85c 1.8v ? v dd ? 3.6v -10 ? +10 % -40c ? t a ?? +125c f21 lprc @ 31 khz ( 2 ) -15 ? 15 % +25c 1.8v ? v dd ? 3.6v -15 ? 15 % -40c ? t a ?? +85c -30 ? +30 % -40c ? t a ?? +125c note 1: frequency calibrated at 25c and 3.3v. osctun bits can be used to compensate for temperature drift. 2: change of lprc frequency as v dd changes.
pic24f16ka102 family ds39927c-page 234 ? 2008-2011 microchip technology inc. table 29-22: ac specifications table 29-23: a/d conversion timing requirements ( 1 ) symbol characteristics min typ max units t lw bclkx high time 20 t cy /2 ?ns t hw bclkx low time 20 (t cy * brgx) + t cy /2 ?ns t bld bclkx falling edge delay from uxtx -50 ? 50 ns t bhd bclkx rising edge delay from uxtx t cy /2 ? 50 ? t cy /2 + 50 ns t wak min. low on uxrx line to cause wake-up ? 1 ? ? s t cts min. low on uxcts line to start transmission t cy ??ns t setup start bit falling edge to system clock rising edge setup time 3 ??ns t stdelay maximum delay in the detection of the start bit falling edge ?? t cy + t setup ns a/d characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min. typ max. units conditions clock parameters ad50 t ad a/d clock period 75 ? ? ns t cy = 75 ns, ad1con3 is in the default state ad51 t rc a/d internal rc oscillator period ? 250 ? ns conversion rate ad55 t conv conversion time ? 12 ? t ad ad56 f cnv throughput rate ? ? 500 ksps av dd ? 2.7v ad57 t samp sample time ? 1 ? t ad ad58 t acq acquisition time 750 ? ? ns (note 2 ) ad59 t swc switching time from convert to sample ?? (note 3 ) ad60 t dis discharge time 0.5 ? ? t ad clock parameters ad61 t pss sample start delay from setting sample bit (samp) 2? 3 t ad note 1: because the sample caps will eventually lose charge, clock rates below 10 khz can affect linearity performance, especially at elevated temperatures. 2: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). 3: on the following cycle of the device clock.
? 2008-2011 microchip technology inc. ds39927c-page 235 pic24f16ka102 family table 29-24: a/d mo dule specifications a/d characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min. typ max. units conditions device supply ad01 av dd module v dd supply greater of v dd ? 0.3 or 1.8 ? lesser of v dd + 0.3 or 3.6 v ad02 av ss module v ss supply v ss ? 0.3 ? v ss + 0.3 v reference inputs ad05 v refh reference voltage high av ss + 1.7 ? av dd v ad06 v refl reference voltage low av ss ?av dd ? 1.7 v ad07 v ref absolute reference voltage av ss ? 0.3 ? av dd + 0.3 v ad08 iv ref reference voltage input current ??200 ? av ref + = 3.3v; sampling ??1.0mav ref + = 3.3v; converting ad09 zv ref reference input impedance ?10k? ? (note 3 ) analog input ad10 v inh -v inl full-scale input span v refl ?v refh v (note 2 ) ad11 v in absolute input voltage av ss ? 0.3 ? av dd + 0.3 v ad12 v inl absolute v inl input voltage av ss ? 0.3 av dd /2 v ad17 r in recommended impedance of analog voltage source ? ? 2.5k ? 10-bit a/d accuracy ad20b n r resolution ? 10 ? bits ad21b inl integral nonlinearity ? 1 2 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad22b dnl differential nonlinearity ? 1 -1 +1.5 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad23b g err gain error ? 1 3 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad24b e off offset error ? 1 2 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad25b monotonicity ? ? ? ? (note 1 ) note 1: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 2: measurements are taken with external v ref + and v ref - used as the a/d voltage reference. 3: impedance during sampling is at 3.3v, 25c. this parameter is for design guidance only and is not tested.
pic24f16ka102 family ds39927c-page 236 ? 2008-2011 microchip technology inc. figure 29-6: clko and i/o ti ming characteristics note: refer to figure 29-4 for load conditions. i/o pin (input) i/o pin (output) di35 old value new value di40 do31 do32 table 29-25: clko and i/ o timing requirements ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. sym characteristic min typ ( 1 ) max units conditions do31 t io r port output rise time ? 10 25 ns do32 t io f port output fall time ? 10 25 ns di35 t inp intx pin high or low time (output) 20 ? ? ns di40 t rbp cnx high or low time (input) 2??t cy note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated.
? 2008-2011 microchip technology inc. ds39927c-page 237 pic24f16ka102 family table 29-26: comp arator timings table 29-27: comparator voltage re ference settling time specifications param no. symbol characteristic min typ max units comments 300 t resp response time * ( 1 ) ? 150 400 ns 301 t mc 2 ov comparator mode change to output valid * ?? 10 ? s * parameters are characterized but not tested. note 1: response time is measured with one comparator input at (v dd ? 1.5)/2, while the other input transitions from v ss to v dd . param no. symbol characteristic min typ max units comments vr310 t set settling time ( 1 ) ??10 ? s note 1: settling time is measured while cvrr = 1 and cvr<3:0> bits transition from ? 0000 ? to ? 1111 ?.
pic24f16ka102 family ds39927c-page 238 ? 2008-2011 microchip technology inc. figure 29-7: reset, watchdog timer, os cillator start-up timer and power-up timer timing characteristics v dd mclr internal por pwrt sysrst system clock watchdog timer reset sy10 sy20 sy13 i/o pins sy13 sy35 sy11 sy12
? 2008-2011 microchip technology inc. ds39927c-page 239 pic24f16ka102 family figure 29-8: baud rate generator output timing table 29-28: reset, watchdog timer, oscill ator start-up timer, power-up timer and brown-out reset timing requirements ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min. typ ( 1 ) max. units conditions sy10 tmcl mclr pulse width (low) 2 ? ? ? s sy11 t pwrt power-up timer period 50 64 90 ms sy12 t por power-on reset delay 1 5 10 ? s sy13 t ioz i/o high-impedance from mclr low or watchdog timer reset ??100ns sy20 t wdt watchdog timer time-out period 0.85 1.0 1.15 ms 1.32 prescaler 3.4 4.0 4.6 ms 1:128 prescaler sy25 t bor brown-out reset pulse width 1 ? ? ? s sy35 t fscm fail-safe clock monitor delay ? 2 2.3 ? s sy45 t rst configuration update time ? 20 ? ? s sy55 t lock pll start-up time ? 1 ? ms sy65 t ost oscillator start-up time ? 1024 ? t osc sy75 t frc fast rc oscillator start-up time ? 1 1.5 ? s sy85 t lprc low-power oscillator start-up time ??100 ? s note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. bclkx uxtx t bld t bhd brgx + 1 * t cy t lw t hw
pic24f16ka102 family ds39927c-page 240 ? 2008-2011 microchip technology inc. figure 29-9: i 2 c? bus start/stop bits timing characteristics (master mode) table 29-29: i 2 c? bus start/stop bit timing requirements (master mode) figure 29-10: i 2 c? bus data timing characteristics (master mode) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial ) -40c ? t a ? +125c for extended param no. symbol characteristic min ( 1 ) max units conditions im30 t su : sta start condition setup time 100 khz mode t cy /2 (brg + 1) ? ? s only relevant for repeated start condition 400 khz mode t cy /2 (brg + 1) ? ? s 1 mhz mode ( 2 ) t cy /2 (brg + 1) ? ? s im31 t hd : sta start condition hold time 100 khz mode t cy /2 (brg + 1) ? ? s after this period, the first clock pulse is generated 400 khz mode t cy /2 (brg + 1) ? ? s 1 mhz mode ( 2 ) t cy /2 (brg + 1) ? ? s im33 t su : sto stop condition setup time 100 khz mode t cy /2 (brg + 1) ? ? s 400 khz mode t cy /2 (brg + 1) ? ? s 1 mhz mode ( 2 ) t cy /2 (brg + 1) ? ? s im34 t hd : sto stop condition 100 khz mode t cy /2 (brg + 1) ? ns hold time 400 khz mode t cy /2 (brg + 1) ? ns 1 mhz mode ( 2 ) t cy /2 (brg + 1) ? ns note 1: brg is the value of the i 2 c? baud rate generator. refer to section 17.3 ?setting baud rate when operating as a bus master? for details. 2: maximum pin capacitance = 10 pf for all i 2 c pins (for 1 mhz mode only). sclx sdax start condition stop condition note: refer to figure 29-4 for load conditions. im31 im30 im34 im33 sclx sdax in sdax out note: refer to figure 29-4 for load conditions. im11 im10 im40 im26 im25 im20 im21 im45
? 2008-2011 microchip technology inc. ds39927c-page 241 pic24f16ka102 family table 29-30: i 2 c? bus data timing requirements (master mode) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min ( 1 ) max units conditions im10 t lo : scl clock low time 100 khz mode t cy /2 (brg + 1) ? ? s 400 khz mode t cy /2 (brg + 1) ? ? s 1 mhz mode ( 2 ) t cy /2 (brg + 1) ? ? s im11 t hi : scl clock high time 100 khz mode t cy /2 (brg + 1) ? ? s 400 khz mode t cy /2 (brg + 1) ? ? s 1 mhz mode ( 2 ) t cy /2 (brg + 1) ? ? s im20 t f : scl sdax and sclx fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode ( 2 ) ?100ns im21 t r : scl sdax and sclx rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode ( 2 ) ?300ns im25 t su : dat data input setup time 100 khz mode 250 ? ns 400 khz mode 100 ? ns 1 mhz mode ( 2 ) tbd ? ns im26 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 1 mhz mode ( 2 ) tbd ? ns im40 t aa : scl output valid from clock 100 khz mode ? 3500 ns 400 khz mode ? 1000 ns 1 mhz mode ( 2 ) ??ns im45 t bf : sda bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s 1 mhz mode ( 2 ) tbd ? ? s im50 c b bus capacitive loading ? 400 pf legend: tbd = to be determined note 1: brg is the value of the i 2 c baud rate generator. refer to section 17.3 ?setting baud rate when operating as a bus master? for details . 2: maximum pin capacitance = 10 pf for all i 2 c pins (for 1 mhz mode only).
pic24f16ka102 family ds39927c-page 242 ? 2008-2011 microchip technology inc. figure 29-11: i 2 c? bus start/stop bits timing characteristics (slave mode) figure 29-12: i 2 c? bus data timing characteristics (slave mode) table 29-31: i 2 c? bus start/stop bit timing requirements (slave mode) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c (industrial ) -40c ? t a ? +125c for extended param no. symbol characteristic min max units conditions is30 t su : sta start condition setup time 100 khz mode 4.7 ? ? s only relevant for repeated start condition 400 khz mode 0.6 ? ? s 1 mhz mode ( 1 ) 0.25 ? ? s is31 t hd : sta start condition hold time 100 khz mode 4.0 ? ? s after this period, the first clock pulse is generated 400 khz mode 0.6 ? ? s 1 mhz mode ( 1 ) 0.25 ? ? s is33 t su : sto stop condition setup time 100 khz mode 4.7 ? ? s 400 khz mode 0.6 ? ? s 1 mhz mode ( 1 ) 0.6 ? ? s is34 t hd : sto stop condition 100 khz mode 4000 ? ns hold time 400 khz mode 600 ? ns 1 mhz mode ( 1 ) 250 ? ns note 1: maximum pin capacitance = 10 pf for all i 2 c? pins (for 1 mhz mode only). sclx sdax start condition stop condition is31 is30 is34 is33 sclx sdax in sdax out is11 is10 is20 is25 is40 is21 is26 is45
? 2008-2011 microchip technology inc. ds39927c-page 243 pic24f16ka102 family table 29-32: i 2 c? bus data timing requirements (slave mode) figure 29-13: start bit edge detection ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c (industrial ) -40c ? t a ? +125c for extended param no. symbol characteristic min max units conditions is10 t lo : scl clock low time 100 khz mode 4.7 ? ? s device must operate at a minimum of 1.5 mhz 400 khz mode 1.3 ? ? s device must operate at a minimum of 10 mhz 1 mhz mode ( 1 ) 0.5 ? ? s is11 t hi : scl clock high time 100 khz mode 4.0 ? ? s device must operate at a minimum of 1.5 mhz 400 khz mode 0.6 ? ? s device must operate at a minimum of 10 mhz 1 mhz mode ( 1 ) 0.5 ? ? s is20 t f : scl sdax and sclx fall time 100 khz mode ? 300 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode ( 1 ) ? 100 ns is21 t r : scl sdax and sclx rise time 100 khz mode ? 1000 ns c b is specified to be from 10 to 400 pf 400 khz mode 20 + 0.1 c b 300 ns 1 mhz mode ( 1 ) ? 300 ns is25 t su : dat data input setup time 100 khz mode 250 ? ns 400 khz mode 100 ? ns 1 mhz mode ( 1 ) 100 ? ns is26 t hd : dat data input hold time 100 khz mode 0 ? ns 400 khz mode 0 0.9 ? s 1 mhz mode ( 1 ) 00.3 ? s is40 t aa : scl output valid from clock 100 khz mode 0 3500 ns 400 khz mode 0 1000 ns 1 mhz mode ( 1 ) 0 350 ns is45 t bf : sda bus free time 100 khz mode 4.7 ? ? s time the bus must be free before a new transmission can start 400 khz mode 1.3 ? ? s 1 mhz mode ( 1 ) 0.5 ? ? s is50 c b bus capacitive loading ? 400 pf note 1: maximum pin capacitance = 10 pf for all i 2 c? pins (for 1 mhz mode only). brgx cycle clock uxrx any value t stdelay t setup t cy start bit detected, brgx started
pic24f16ka102 family ds39927c-page 244 ? 2008-2011 microchip technology inc. figure 29-14: input cap ture timings table 29-33: input capture table 29-34: output capture figure 29-15: output compare timings param. no. symbol characteristic min max units conditions ic10 tccl icx input low time ? synchronous timer no prescaler t cy + 20 ? ns must also meet parameter ic15 with prescaler 20 ? ns ic11 tcch icx input low time ? synchronous timer no prescaler t cy + 20 ? ns must also meet parameter ic15 with prescaler 20 ? ns ic15 tccp icx input period ? synchronous timer 2 * t cy + 40 n ?nsn = prescale value (1, 4, 16) param. no. symbol characteristic min max units conditions oc11 t cc r oc1 output rise time ? 10 ns ? ?ns oc10 t cc f oc1 output fall time ? 10 ns ?? ns icx pin (input capture mode) ic10 ic11 ic15 ocx oc11 oc10 (output compare or pwm mode)
? 2008-2011 microchip technology inc. ds39927c-page 245 pic24f16ka102 family figure 29-16: pwm modul e timing requirements table 29-35: pwm timing requirements param. no. symbol characteristic min typ ? max units conditions oc15 t fd fault input to pwm i/o change ? ? 25 ns v dd = 3.0v, -40 ? c to +125 ? c oc20 t fh fault input pulse width 50 ? ? ns v dd = 3.0v, -40 ? c to +125 ? c ? data in ?typ? column is at 5v, 25 ? c unless otherwise stated. these parameters are for design guidance only and are not tested. ocfx pwm oc20 oc15
pic24f16ka102 family ds39927c-page 246 ? 2008-2011 microchip technology inc. figure 29-17: spix modul e master mode timing characteristics (cke = 0 ) table 29-36: spix master mode timing requirements (cke = 0 ) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +125c for extended param no. symbol characteristic min typ ( 1 ) max units conditions sp10 tscl sckx output low time ( 2 ) t cy /2 ? ? ns sp11 tsch sckx output high time ( 2 ) t cy /2 ? ? ns sp20 tscf sckx output fall time ( 3 ) ?1025ns sp21 tscr sckx output rise time ( 3 ) ?1025ns sp30 tdof sdox data output fall time ( 3 ) ?1025ns sp31 tdor sdox data output rise time ( 3 ) ?1025ns sp35 tsch2dov, tscl2dov sdox data output valid after sckx edge ? ? 30 ns sp40 tdiv2sch, tdiv2scl setup time of sdix data input to sckx edge 20 ? ? ns sp41 tsch2dil, tscl2dil hold time of sdix data input to sckx edge 20 ? ? ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: the minimum clock period for sckx is 100 ns; therefore, the clock generated in master mode must not violate this specification. 3: assumes 50 pf load on all spix pins. sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix sp11 sp10 sp40 sp41 sp21 sp20 sp35 sp20 sp21 msb lsb bit 14 - - - - - -1 lsb in bit 14 - - - -1 sp30 sp31 msb in
? 2008-2011 microchip technology inc. ds39927c-page 247 pic24f16ka102 family figure 29-18: spix modul e master mode timing characteristics (cke = 1 ) table 29-37: spix module master mo de timing requirements (cke = 1 ) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ ( 1 ) max units conditions sp10 tscl sckx output low time ( 2 ) t cy /2 ? ? ns sp11 tsch sckx output high time ( 2 ) t cy /2 ? ? ns sp20 tscf sckx output fall time ( 3 ) ?1025ns sp21 tscr sckx output rise time ( 3 ) ?1025ns sp30 tdof sdox data output fall time ( 3 ) ?1025ns sp31 tdor sdox data output rise time ( 3 ) ?1025ns sp35 tsch2dov, tscl2dov sdox data output valid after sckx edge ??30ns sp36 tdov2sc, tdov2scl sdox data output setup to first sckx edge 30 ? ? ns sp40 tdiv2sch, tdiv2scl setup time of sdix data input to sckx edge 20 ? ? ns sp41 tsch2dil, tscl2dil hold time of sdix data input to sckx edge 20 ? ? ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: the minimum clock period for sckx is 100 ns. therefore, the clock generated in master mode must not violate this specification. 3: assumes 50 pf load on all spix pins. sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sdix sp36 sp30,sp31 sp35 msb bit 14 - - - - - -1 lsb in bit 14 - - - -1 lsb sp11 sp10 sp21 sp20 sp41 msb in sp40 sp20 sp21
pic24f16ka102 family ds39927c-page 248 ? 2008-2011 microchip technology inc. figure 29-19: spix modul e slave mode timing characteristics (cke = 0 ) table 29-38: spix module slave mode timing requirements (cke = 0 ) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ ( 1 ) max units conditions sp70 tscl sckx input low time 30 ? ? ns sp71 tsch sckx input high time 30 ? ? ns sp72 tscf sckx input fall time ( 2 ) ?1025ns sp73 tscr sckx input rise time ( 2 ) ?1025ns sp30 tdof sdox data output fall time ( 2 ) ?1025ns sp31 tdor sdox data output rise time ( 2 ) ?1025ns sp35 tsch2dov, tscl2dov sdox data output valid after sckx edge ? ? 30 ns sp40 tdiv2sch, tdiv2scl setup time of sdix data input to sckx edge 20 ? ? ns sp41 tsch2dil, ts c l 2 d i l hold time of sdix data input to sckx edge 20 ? ? ns sp50 tssl2sch, tssl2scl ssx to sckx ? or sckx input 120 ? ? ns sp51 tssh2doz ssx ? to sdox output high-impedance ( 3 ) 10 ? 50 ns sp52 tsch2ssh ts c l 2 s s h ssx after sckx edge 1.5 t cy + 40 ? ? ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: the minimum clock period for sckx is 100 ns. therefore, the clock generated in master mode must not violate this specification. 3: assumes 50 pf load on all spix pins. ssx sckx (ckp = 0) sckx (ckp = 1) sdox sdi sp50 sp40 sp41 sp30,sp31 sp51 sp35 sdix msb lsb bit 14 - - - - - -1 bit 14 - - - -1 lsb in sp52 sp73 sp72 sp72 sp73 sp71 sp70 msb in
? 2008-2011 microchip technology inc. ds39927c-page 249 pic24f16ka102 family figure 29-20: spix modul e slave mode timing characteristics (cke = 1 ) ssx sckx (ckp = 0 ) sckx (ckp = 1 ) sdox sp60 sdix sp30,sp31 msb bit 14 - - - - - -1 lsb sp51 bit 14 - - - -1 lsb in sp35 sp52 sp52 sp73 sp72 sp72 sp73 sp71 sp70 sp40 sp41 sp50 msb in table 29-39: spix module slave mode timing requirements (cke = 1 ) ac characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c ? t a ? +85c for industrial -40c ? t a ? +125c for extended param no. symbol characteristic min typ ( 1 ) max units conditions sp70 tscl sckx input low time 30 ? ? ns sp71 tsch sckx input high time 30 ? ? ns sp72 tscf sckx input fall time ( 2 ) ?1025ns sp73 tscr sckx input rise time ( 2 ) ?1025ns sp30 tdof sdox data output fall time ( 2 ) ?1025ns sp31 tdor sdox data output rise time ( 2 ) ?1025ns sp35 tsch2dov, tscl2dov sdox data output valid after sckx edge ? ? 30 ns sp40 tdiv2sch, tdiv2scl setup time of sdix data input to sckx edge 20 ? ? ns sp41 tsch2dil, tscl2dil hold time of sdix data input to sckx edge 20 ? ? ns sp50 tssl2sch, tssl2scl ssx ? to sckx ? or sckx ? input 120 ? ? ns sp51 tssh2doz ssx ? to sdox output high-impedance ( 3 ) 10 ? 50 ns sp52 tsch2ssh tscl2ssh ssx ? after sckx edge 1.5 t cy + 40 ? ? ns sp60 tssl2dov sdox data output valid after ssx edge ? ? 50 ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: the minimum clock period for sckx is 100 ns. therefore, the clock generated in master mode must not violate this specification. 3: assumes 50 pf load on all spix pins.
pic24f16ka102 family ds39927c-page 250 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 251 pic24f16ka102 family 30.0 packaging information 30.1 package marking information 28-lead spdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic24f16ka102 1110017 3 e 28-lead ssop xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic24f08ka 102-i/ss 1110017 3 e 20-lead pdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example 20-lead ssop xxxxxxxxxxx xxxxxxxxxxx yywwnnn example pic24f16ka 101-i/ss 1110017 3 e -i/sp legend: xx...x product-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e -i/p pic24f16ka101 1110017 3 e
pic24f16ka102 family ds39927c-page 252 ? 2008-2011 microchip technology inc. 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 24f16ka 102-i/ml 1110017 3 e 28-lead soic (.300?) xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example 20-lead soic (.300?) xxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxx yywwnnn example pic24f16ka101 -i/so 1110017 3 e 20-lead qfn example 3 e xxxxxx xxxxxx yywwnnn xxxxxx pic24f 16ka101 1110017 -i/mq pic24f16ka102 -i/so 1110017 3 e
? 2008-2011 microchip technology inc. ds39927c-page 253 pic24f16ka102 family 30.2 package details the following sections give the technical details of the packages. 
    
     

       !" # $% &" '  ()"&'"!&)  & #*&&  & #    + % &,  & !& - ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #/
!#   ' !  #&   
.0 1,2 1 !' !  &  $ & " !**&"&&   !   3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 7,8. ' !9'&! 7 7: ; 7"') %! 7  & 1, 
& &    < <  # # 4 4 !!   -  1 ! & &     < < "# &"# =#& . - - - # # 4 =#& .   > :  9  &  > - ? 
& &   9  -  9 #4 !!  >   6
9 #=#& )  ?  9* 9 #=#& )  >  :  *
 + 1 < < - n e1 note 1 d 123 a a1 a2 l e b1 b e c eb 
    * , 1
pic24f16ka102 family ds39927c-page 254 ? 2008-2011 microchip technology inc.   !"
    !
     !

      !" # $% &" '  ()"&'"!&)  & #*&&  & #    + % &,  & !& - ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #/
!#   ' !  #&   
.0 1,2 1 !' !  &  $ & " !**&"&&   !   3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 7,8. ' !9'&! 7 7: ; 7"') %! 7 > & 1, 
& &    < <  # # 4 4 !!   -  1 ! & &     < < "# &"# =#& .  - -- # # 4 =#& .  >  :  9  &  - -?  
& &   9  -  9 #4 !!  >   6
9 #=#& )    9* 9 #=#& )  >  :  *
 + 1 < < - note 1 n 12 d e1 eb c e l a2 e b b1 a1 a 3 
    * , 1
? 2008-2011 microchip technology inc. ds39927c-page 255 pic24f16ka102 family 
  !#$" ! %  !!  &'   !!%
      !" # $% &" '  ()"&'"!&)  & #*&&  & #    ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #''
!#  - ' !  #&   
.0 1,2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! !   3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 99.. ' !9'&! 7 7: ; 7"') %! 7  & ?1, :  8  &  < <  # # 4 4 !!  ?  > & #%%   < < :  =#& .  > > # # 4 =#& .  - ? :  9  &  ?   3&9  & 9    3&
& 9 .3 9 #4 !!   <  3&  @ @ >@ 9 #=#& )  < -> l l1 a2 c e b a1 a 12 note 1 e1 e d n 
    * , 1
pic24f16ka102 family ds39927c-page 256 ? 2008-2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2008-2011 microchip technology inc. ds39927c-page 257 pic24f16ka102 family  
  !#$" ! %  !!  &'   !!%
      !" # $% &" '  ()"&'"!&)  & #*&&  & #    ' !! #.#&"# '#% !
&"!!#% !
&"!!! & $ #''
!#  - ' !  #&   
.0 1,2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! !   3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 99.. ' !9'&! 7 7: ; 7"') %! 7 > & ?1, :  8  &  < <  # # 4 4 !!  ?  > & #%%   < < :  =#& .  > > # # 4 =#& .  - ? :  9  &     3&9  & 9    3&
& 9 .3 9 #4 !!   <  3&  @ @ >@ 9 #=#& )  < -> l l1 c a2 a1 a e e1 d n 1 2 note 1 b e 
    * , -1
pic24f16ka102 family ds39927c-page 258 ? 2008-2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2008-2011 microchip technology inc. ds39927c-page 259 pic24f16ka102 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16ka102 family ds39927c-page 260 ? 2008-2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2008-2011 microchip technology inc. ds39927c-page 261 pic24f16ka102 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16ka102 family ds39927c-page 262 ? 2008-2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2008-2011 microchip technology inc. ds39927c-page 263 pic24f16ka102 family note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
pic24f16ka102 family ds39927c-page 264 ? 2008-2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2008-2011 microchip technology inc. ds39927c-page 265 pic24f16ka102 family 20-lead plastic quad flat, no lead package (mq) ? 5x5x0.9 mm body [qfn] note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging microchip technology drawing c04-120a
pic24f16ka102 family ds39927c-page 266 ? 2008-2011 microchip technology inc. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging
? 2008-2011 microchip technology inc. ds39927c-page 267 pic24f16ka102 family  
  ( )  *  
"+ ,  -.-   () / # '&&  0  + #      !" # $% &" '  ()"&'"!&)  & #*&&  & #     4 !! *! " & # - ' !  #&   
.0 1,2 1 !' !  &  $ & " !**&"&&   ! .32  %   ' !("!" *&"&&   (%%' &
"
! !   3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4  6&! 99.. ' !9'&! 7 7: ; 7"') %! 7 > & ?1, :  8  &  >   & #%%     ,& &4 !! - .3 :  =#& . ?1, .$
! # #=#& . -? -  :  9  &  ?1, .$
! # #9  &  -? -  ,& &=#& ) - - - ,& &9  & 9    ,& & & .$
! # # a  < < d exposed d2 e b k e2 e l n note 1 1 2 2 1 n a a1 a3 top view bottom view pad 
    * , 1
pic24f16ka102 family ds39927c-page 268 ? 2008-2011 microchip technology inc.  
  ( )  *  
"+ ,  -.-   () / # '&&  0  + #   3& '!&" &
4 # * !(
 ! ! & 
 4  
% & & # & &&
255***'
'5
4 
? 2008-2011 microchip technology inc. ds39927c-page 269 pic24f16ka102 family appendix a: revision history revision a (november 2008) original data sheet for the pic24f16ka102 family of devices. revision b (march 2009) section 29.0 ?electrical characteristics? was revised and minor text edits were made throughout the document. revision c (october 2011) ? changed all instances of dswsrc to dswake. ? corrected example 5-2 . ? corrected example 5-4 . ? corrected example 6-1 . ? corrected example 6-3 . ? added a comment to example 6-5 . ? corrected figure 9-1 to connect the sosci and sosco pins to the schmitt trigger correctly. ? added register descriptions for pmd1, pmd2, pmd3 and pmd4. ? added note that rtcc will run in reset. ? corrected time values of adcs (ad1con3<5:0>). ? corrected ch0sb and ch0sa (ad1chs<11:8> and ad1chs<3:0>) to correctly reference av dd and an3. ? added description of pgcf15 and pgcf14 (ad1pcfg<15:14>). ?edited figure 22-2 to correctly reference ric and the a/d capacitance. ? changed all references from ctedg1 to cted1. ? changed all references from ctedg2 to cted2. ? changed description of cmidl: it used to say it disables all comparators in idle, now only disables interrupts in idle mode. ? changed all references of rtccksel to rtcosc. ? changed all references of dslpbor to dsboren. ? changed all references of dswcksel to dswdtosc ? imported figure 40-9 from pic24f frm, section 40. ? added spec for bor hysteresis. ? edited note 1 for table 29-5 to further describe lpbor. ? edited max values of dc20d and dc20e on table 29-6 . ? edited typical value for dc61-dc61c in table 29-8 . ? edited note 2 of ta b l e 2 9 - 8 . ? added note 5 to table 29-9 . ? added table 29-15 . ? added ad08 and ad09 in table 29-26 . ? added note 3 to table 29-26 . ? imported figure 40.10 from pic24f frm, section 40. ? deleted t vreg spec. ? imported figure 15-5 from pic24f frm, section 15. ? imported table 15-4 from pic24f frm, section 15. ? imported figure 16-22 from pic24f frm, section 16. ? imported table 16-9 from pic24f frm, section 16. ? imported figure 16-23 from pic24f frm, section 16. ? imported table 16-10 from pic24f frm, section 16. ? imported figure 21-24 from pic24f frm. section 21. ? imported figure 21-25 from pic24f frm, section 21. ? imported table 21-5 from pic24f frm, section 21. ? imported figure 23-17 from pic24f frm, section 23. ? imported table 23-3 from pic24f frm, section 23. ? imported figure 23-18 from pic24f frm, section 23. ? imported table 23-4 from pic24f frm, section 23. ? imported figure 23-19 from pic24f frm, section 23. ? imported table 23-5 from pic24f frm, section 23. ? imported figure 23-20 from pic24f frm, section 23. ? imported table 23-6 from pic24f frm, section 23. ? imported figure 24-33 from pic24f frm, section 24. ? imported table 24-6 from pic24f frm, section 24. ? imported figure 24-34 from pic24f frm, section 24. ? imported table 24-7 from pic24f frm, section 24. ? imported figure 24-35 from pic24f frm, section 24. ? imported table 24-8 from pic24f frm, section 24. ? imported figure 24-36 from pic24f frm, section 24. ? imported table 24-9 from pic24f frm, section 24.
pic24f16ka102 family ds39927c-page 270 ? 2008-2011 microchip technology inc. notes:
? 2008-2011 microchip technology inc. ds39927c-page 271 pic24f16ka102 family index a a/d 10-bit high-speed a/d converter ............................ 173 a/d characteristics conversion timing requirements ............................ 234 module specifications .............................................. 235 a/d converter analog input model .................................................. 181 transfer function ..................................................... 182 ac characteristics capacitive loading requirements on output pins ...................................................... 231 comparator timings ................................................ 237 comparator voltage reference settling time specifications .......................................... 237 input capture ........................................................... 244 internal rc accuracy ............................................... 233 load conditions for device timing specifications ................................................... 231 output capture ........................................................ 244 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset timing requirements ....................................... 239 specifications ........................................................... 234 assembler mpasm assembler .................................................. 204 b baud rate generator setting as a bus master ........................................... 141 block diagrams 10-bit high-speed a/d converter ............................ 174 16-bit timer1 ........................................................... 115 accessing program memory with table instructions .............................................. 43 call stack frame ..................................................... 41 comparator module ................................................. 183 comparator voltage reference ............................... 187 cpu programmer?s model ......................................... 25 crc reconfigured for polynomial ........................... 168 crc shifter details .................................................. 167 ctmu connections and internal configuration for capacitance measurement .............................. 189 ctmu typical connections and internal configuration for pulse delay generation ....... 190 ctmu typical connections and internal configuration for time measurement .............. 190 data access from program space address generation ........................................... 42 data eeprom addressing with tblpag, nvm address registers .................................... 53 high/low-voltage detect (hlvd) ............................ 171 i 2 c module ............................................................... 140 individual comparator configurations ...................... 184 input capture ........................................................... 123 output compare ...................................................... 128 pic24f cpu core ..................................................... 24 pic24f16ka102 family (general) ............................ 12 psv operation ........................................................... 44 reset system ............................................................ 57 rtcc ....................................................................... 155 shared i/o port structure ........................................ 113 simplified uart ...................................................... 147 spi1 module (enhanced buffer mode) .................... 133 spi1 module (standard buffer mode) ..................... 132 system clock ............................................................. 91 timer2 (16-bit synchronous mode) ......................... 119 timer2/3 (32-bit mode) ............................................ 118 timer3 (16-bit synchronous mode) ......................... 119 watchdog timer (wdt) ........................................... 201 brown-out reset (bor) ..................................................... 61 c c compilers mplab c18 ............................................................. 204 charge time measurement unit. see ctmu. code examples data eeprom bulk erase ........................................ 55 data eeprom unlock sequence ............................. 51 erasing a program memory row, ?c? language code ............................................ 48 erasing a program memory row, assembly language code ................................ 48 i/o port write/read ................................................. 114 initiating a programming sequence, ?c? language code ............................................ 50 initiating a programming sequence, assembly language code ................................ 50 loading the write buffers, ?c? language code ......... 49 loading the write buffers, assembly language code ................................................. 49 pwrsav instruction syntax ................................... 101 reading data eeprom using the tblrd command ............................................. 56 sequence for clock switching ................................... 98 setting the rtcwren bit ....................................... 156 single-word erase .................................................... 54 single-word write to data eeprom ........................ 55 code protection ............................................................... 202 comparator ...................................................................... 183 comparator voltage reference ....................................... 187 configuration ........................................................... 187 configuration bits ............................................................ 193 core features ...................................................................... 9 cpu arithmetic (logic unit (alu) ...................................... 27 control registers ....................................................... 26 core registers ........................................................... 24 programmer?s model ................................................. 23 crc operation in power save modes ............................. 168 user interface .......................................................... 168 ctmu measuring capacitance ........................................... 189 measuring time ....................................................... 190 pulse generation and delay .................................... 190 customer change notification service ............................ 275 customer notification service ......................................... 275 customer support ............................................................ 275
pic24f16ka102 family ds39927c-page 272 ? 2008-2011 microchip technology inc. d data eeprom bulk erase .................................................................. 55 erasing ....................................................................... 54 operations ................................................................. 53 programming reading data eeprom .................................... 56 single-word write .............................................. 55 data memory address space ........................................................... 31 memory map .............................................................. 31 near data space ....................................................... 32 organization, alignment ............................................. 32 sfr space ................................................................. 32 software stack ........................................................... 41 space width ............................................................... 31 dc characteristics brown-out reset trip points .................................... 219 comparator specifications ....................................... 230 comparator voltage reference specifications ........ 230 ctmu current source specifications ...................... 230 data eeprom memory ........................................... 229 high/low-voltage detect ......................................... 218 i/o pin input specifications ...................................... 227 i/o pin output specifications ................................... 228 idle current i idle ...................................................... 222 internal voltage references .................................... 230 operating current i dd .............................................. 220 power-down current i pd ......................................... 224 program memory ..................................................... 229 temperature and voltage specific ations ................. 218 thermal operating conditions ................................. 217 thermal packaging characteristics ......................... 217 deep sleep checking, clearing status ....................................... 104 entering .................................................................... 102 sequence ................................................. 102, 103 exiting ...................................................................... 103 i/o pins .................................................................... 103 por ......................................................................... 104 sequence summary ................................................ 104 wdt ......................................................................... 104 deep sleep bor (dsbor) ............................................... 61 development support ...................................................... 203 device features (summary) .............................................. 11 doze mode ....................................................................... 107 e electrical characteristics absolute maximum ratings ..................................... 215 v/f graphs (industrial, extended) ........................... 216 v/f graphs (industrial) ............................................. 216 equations a/d conversion clock period .................................. 181 baud rate reload calculation ................................. 141 calculating the pwm period .................................... 126 calculation for maximum pwm resolution .............. 126 crc ......................................................................... 167 device and spi clock speed relationship .............. 138 uart baud rate with brgh = 0 ............................ 148 uart baud rate with brgh = 1 ............................ 148 errata ................................................................................... 8 examples baud rate error calculation (brg) ......................... 148 pwm frequencies, resolutions at 16 mips ............ 127 pwm frequencies, resolutions at 4 mips .............. 127 pwm period, duty cycle calculations ..................... 127 f flash and data eeprom programming control registers ............................................... 51 flash and data eeprom programming control registers nvm address registers (nvmadru, nvmadr ................................................... 53 nvmcon ........................................................... 51 nvmkey ........................................................... 51 flash program memory control registers ....................................................... 46 enhanced icsp operation ........................................ 46 programming algorithm ............................................. 48 programming operations ........................................... 46 rtsp operation ........................................................ 46 table instructions ...................................................... 45 h high/low-voltage detect (hlvd) .................................... 171 i i/o ports analog pins configuration ....................................... 114 input change notification ........................................ 114 open-drain configuration ........................................ 114 parallel (pio) ........................................................... 113 i 2 c clock rates ............................................................. 141 communicating as master in single master environment .................................................... 139 pin remapping options ........................................... 139 reserved addresses ............................................... 141 slave address masking ........................................... 141 in-circuit debugger .......................................................... 202 in-circuit serial programming (icsp) .............................. 202 input capture ................................................................... 123 instruction set opcode symbols ..................................................... 208 overview .................................................................. 209 summary ................................................................. 207 inter-integrated circuit. see i 2 c. internet address .............................................................. 275 interrupts alternate interrupt vector table (aivt) ..................... 63 control and status registers ..................................... 66 implemented vectors ................................................. 65 interrupt service routine (isr) .................................. 90 interrupt vector table (ivt) ....................................... 63 reset sequence ........................................................ 63 setup and service procedures .................................. 90 trap service routine (tsr) ...................................... 90 trap vectors .............................................................. 65 vector table .............................................................. 64
? 2008-2011 microchip technology inc. ds39927c-page 273 pic24f16ka102 family m microchip internet web site ............................................. 275 mplab asm30 assembler, linker, librarian .................. 204 mplab integrated development environment software .............................................. 203 mplab pm3 device programmer ................................... 206 mplab real ice in-circuit emulator system ................ 205 mplink object linker/mplib object librarian ............... 204 n near data space ............................................................... 32 o oscillator configuration bit values for clock selection .................................... 92 clock switching .......................................................... 97 sequence ........................................................... 97 cpu clocking scheme .............................................. 92 initial configuration on por ...................................... 92 reference clock output ............................................. 98 output compare continuous output pulse generation ...................... 125 single output pulse generation .............................. 125 p packaging details ...................................................................... 253 marking .................................................................... 251 pinout descriptions ...................................................... 13?16 power-saving features ................................................... 101 clock frequency, clock switching ........................... 101 instruction-based modes ......................................... 101 deep sleep ...................................................... 102 idle ................................................................... 102 sleep ................................................................ 101 product identification system .......................................... 277 program and data memory access using table instructions ................................ 43 program space visibility ............................................ 44 program and data memory spaces interfacing, addressing .............................................. 41 program memory address space ........................................................... 29 configuration word addresses .................................. 30 memory map .............................................................. 29 program verification ........................................................ 202 programmable cyclic redundancy check (crc) generator ................................................................. 167 pulse-width modulation. see pwm. r reader response ............................................................ 276 register maps a/d ............................................................................. 38 clock control ............................................................. 40 cpu core ................................................................... 33 crc ........................................................................... 39 ctmu ......................................................................... 38 deep sleep ................................................................ 40 dual comparator ........................................................ 39 i 2 c .............................................................................. 36 icn ............................................................................. 34 input capture ............................................................. 35 interrupt controller ..................................................... 34 nvm ........................................................................... 40 output compare ........................................................ 35 pad configuration ...................................................... 37 pmd ........................................................................... 40 porta ...................................................................... 37 portb ...................................................................... 37 rtcc ......................................................................... 39 spi ............................................................................. 36 timer ......................................................................... 35 uart ......................................................................... 36 registers ad1chs (a/d input select) ..................................... 178 ad1con1 (a/d control 1) ....................................... 175 ad1con2 (a/d control 2) ....................................... 176 ad1con3 (a/d control 3) ....................................... 177 ad1cssl (a/d input scan select, low) ................. 180 ad1pcfg (a/d port configuration) ........................ 179 alcfgrpt (alarm configuration) .......................... 159 alminsec (alarm minutes and seconds value) ............................................... 163 almthdy (alarm month and day value) ............... 162 alwdhr (alarm weekday and hours value) ........ 162 clkdiv (clock divider) ............................................. 95 cmstat (comparator status) ................................ 186 cmxcon (comparator x control) ........................... 185 corcon (cpu control) ..................................... 27, 68 crccon (crc control) ......................................... 169 crcxor (crc xor polynomial) .. ........................ 170 ctmucon (ctmu control) .................................... 191 ctmuicon (ctmu current control) ...................... 192 cvrcon (comparator voltage reference control) .......................................... 188 devid (device id) ................................................... 200 devrev (device revision) ..................................... 200 dscon (deep sleep control) ................................. 105 dswake (deep sleep wake-up source) ............... 106 fbs (boot segment configuration) ......................... 193 fds (deep sleep configuration) ............................. 199 fgs (general segment configuration) ................... 194 ficd (in-circuit debugger configuration) ............... 198 fosc (oscillator configuration) .............................. 195 foscsel (oscillator selection configuration) ....... 194 fpor (reset configuration) ................................... 197 fwdt (watchdog timer configuration) .................. 196 hlvdcon (high/low-voltage detect control) ....... 172 i2c1con (i2c1 control) ......................................... 142 i2c1msk (i2c1 slave mode address mask) .......... 146 i2c1stat (i2c1 status) .......................................... 144 ic1con (input capture 1 control) .......................... 124 iec0 (interrupt enable control 0) .............................. 75 iec1 (interrupt enable control 1) .............................. 76 iec3 (interrupt enable control 3) .............................. 77 iec4 (interrupt enable control 4) .............................. 78 ifs0 (interrupt flag status 0) .................................... 71 ifs1 (interrupt flag status 1) .................................... 72 ifs3 (interrupt flag status 3) .................................... 73 ifs4 (interrupt flag status 4) .................................... 74 intcon1 (interrupt control 1) .................................. 69 intcon2 (interrupt control 2) .................................. 70 inttreg interrupt control and status ...................... 89 ipc0 (interrupt priority control 0) .............................. 79 ipc1 (interrupt priority control 1) .............................. 80 ipc15 (interrupt priority control 15) .......................... 86 ipc16 (interrupt priority control 16) .......................... 87 ipc18 (interrupt priority control 18) .......................... 88 ipc19 (interrupt priority control 19) .......................... 88
pic24f16ka102 family ds39927c-page 274 ? 2008-2011 microchip technology inc. ipc2 (interrupt priority control 2) .............................. 81 ipc3 (interrupt priority control 3) .............................. 82 ipc4 (interrupt priority control 4) .............................. 83 ipc5 (interrupt priority control 5) .............................. 84 ipc7 (interrupt priority control 7) .............................. 85 minsec (rtcc minutes and seconds value) ........ 161 mthdy (rtcc month and day value) ................... 160 nvmcon (flash memory control) ............................ 47 nvmcon (nonvolatile memory control) ................... 52 oc1con (output compare 1 control) .................... 129 osccon (oscillator control) .................................... 93 osctun (frc oscillator tune) ................................ 96 padcfg1 (pad configuration control) ...................... 130, 146, 158 pmd1 (peripheral module disable 1) ...................... 108 pmd2 (peripheral module disable 2) ...................... 109 pmd3 (peripheral module disable 3) ...................... 110 pmd4 (peripheral module disable 4) ...................... 111 rcfgcal (rtcc calibration and configuration) .................................................. 157 rcon (reset control) ............................................... 58 refocon (reference oscillator control) ................. 99 spi1con1 (spi1 control 1) .................................... 136 spi1con2 (spi1 control 2) .................................... 137 spi1stat (spi1 status and control) ...................... 134 sr (alu status) .............................................. 26, 67 t1con (timer1 control) .......................................... 116 t2con (timer2 control) .......................................... 120 t3con (timer3 control) .......................................... 121 uxmode (uartx mode) ......................................... 150 uxrxreg (uartx receive) ................................... 154 uxsta (uartx status and control) ........................ 152 uxtxreg (uartx transmit) .................................. 154 wkdyhr (rtcc weekday and hours value) ........ 161 year (rtcc year value) ....................................... 160 resets clock source selection .............................................. 60 delay times for various device resets .................... 60 device times ............................................................. 60 rcon flags operation .............................................. 59 sfr states ................................................................. 61 revision history ............................................................... 269 rtcc ............................................................................... 155 alarm configuration ................................................. 164 alarm mask settings (figure) .................................... 165 calibration ................................................................ 164 register mapping ..................................................... 156 source clock ............................................................ 155 selection .......................................................... 156 write lock ................................................................ 156 s selective peripheral power control ................................. 107 serial peripheral interface. see spi. sfr space ......................................................................... 32 software simulator (mplab sim) .................................... 205 software stack ................................................................... 41 t timer1 .............................................................................. 115 timer2/3 ........................................................................... 117 timing diagrams baud rate generator output ........................... 239, 240 brown-out reset characteristics ............................. 219 clko and i/o timing .............................................. 236 external clock .......................................................... 232 i 2 c bus data (master mode) ................................... 240 i 2 c bus data (slave mode) ..................................... 242 i 2 c bus start/stop bits (master mode) .................... 240 i 2 c bus start/stop bits (slave mode) ...................... 242 input capture ........................................................... 244 output compare ...................................................... 244 pwm requirements ................................................. 245 reset, watchdog timer. oscillator start-up timer, power-up timer characteristics ........... 238 spix master mode (cke = 0) .................................. 246 spix master mode (cke = 1) .................................. 247 spix slave mode (cke = 0) .................................... 248 spix slave mode (cke = 1) .................................... 249 start bit edge detection .......................................... 243 timing requirements clko and i/o .......................................................... 236 external clock .......................................................... 232 i 2 c bus data (master mode) ........................... 240, 241 i 2 c bus data (slave mode) ..................................... 243 i 2 c bus start/stop bit (slave mode) ........................ 242 pll clock specifications ......................................... 233 pwm ........................................................................ 245 spix master mode (cke = 0) .................................. 246 spix master mode (cke = 1) .................................. 247 spix slave mode (cke = 0) .................................... 248 spix slave mode (cke = 1) .................................... 249 u uart ............................................................................... 147 baud rate generator (brg) ................................... 148 break and sync transmit sequence ....................... 149 irda support ............................................................ 149 operation of uxcts and uxrts control pins ........ 149 receiving in 8-bit or 9-bit data mode ...................... 149 transmitting in 8-bit data mode .............................. 149 transmitting in 9-bit data mode .............................. 149 w watchdog timer deep sleep (dswdt) ............................................. 202 watchdog timer (wdt) ................................................... 201 windowed operation ............................................... 201 www address ................................................................ 275 www, on-line support ........ .............................................. 8
? 2008-2011 microchip technology inc. ds39927c-page 275 pic24f16ka102 family the microchip web site microchip provides online support via our www site at www.microchip.com . this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com . under ?support?, click on ?customer change notification? and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://microchip.com/support
pic24f16ka102 family ds39927c-page 276 ? 2008-2011 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip product. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to: technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds39927c pic24f16ka102 family 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2008-2011 microchip technology inc. ds39927c-page 277 pic24f16ka102 family product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . architecture 24 = 16-bit modified harvard without dsp flash memory family f = flash program memory product group ka1 = general purpose microcontrollers pin count 01 = 20-pin 02 = 28-pin temperature range i = -40 ? c to +85 ? c (industrial) e= -40 ? c to +125 ? c (extended) package sp = spdip so = soic ss = ssop ml = qfn p=pdip pattern three-digit qtp, sqtp, code or special requirements (blank otherwise) es = engineering sample examples: a) pic24f16ka102-i/ml: general purpose, 16-kbyte program memory, 28-pin, industrial temp., qfn package. microchip trademark architecture flash memory family program memory size (kb) product group pin count temperature range package pattern pic 24 f 16 ka1 02 t - i / pt - xxx tape and reel flag (if applicable)
ds39927c-page 278 ? 2008-2011 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://www.microchip.com/ support web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 indianapolis noblesville, in tel: 317-773-8323 fax: 317-773-5453 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8569-7000 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - chongqing tel: 86-23-8980-9588 fax: 86-23-8980-9500 china - hangzhou tel: 86-571-2819-3187 fax: 86-571-2819-3189 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4123 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-5778-366 fax: 886-3-5770-955 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-330-9305 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 worldwide sales and service 08/02/11


▲Up To Search▲   

 
Price & Availability of PIC24F16KA102T-I

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X